#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ sqlite3_stmt;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ SQLITE_OK;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *, long long, long long, long long);
scalar_t__ sqlite3_close(int /*<<< orphan*/ *);
long long sqlite3_column_int(int /*<<< orphan*/ *, int);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_open(char *, int /*<<< orphan*/ **);
scalar_t__ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int,
                              int /*<<< orphan*/ **, int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void enumerate(char *fname) {
  sqlite3 *db;
  if (sqlite3_open(fname, &db) != SQLITE_OK) {
    fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
    exit(EXIT_FAILURE);
  }
  char *sql = "SELECT zoom_level, tile_column, tile_row from tiles;";
  sqlite3_stmt *stmt;
  if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
    fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
    exit(EXIT_FAILURE);
  }
  while (sqlite3_step(stmt) == SQLITE_ROW) {
    long long zoom = sqlite3_column_int(stmt, 0);
    long long x = sqlite3_column_int(stmt, 1);
    long long y = sqlite3_column_int(stmt, 2);
    y = (1LL << zoom) - 1 - y;
    printf("%s %lld %lld %lld\n", fname, zoom, x, y);
  }
  sqlite3_finalize(stmt);
  if (sqlite3_close(db) != SQLITE_OK) {
    fprintf(stderr, "%s: could not close database: %s\n", fname,
            sqlite3_errmsg(db));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<enumerate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
je     120a <enumerate+0x6a>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe09(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdf7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    0x2db1(%rip),%rcx
cmp    (%rcx),%rax
je     1281 <enumerate+0xe1>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xdcf(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    1286 <enumerate+0xe6>
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%rax
jne    130b <enumerate+0x16b>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <sqlite3_column_int@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1050 <sqlite3_column_int@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rcx
mov    $0x1,%eax
shl    %cl,%rax
sub    $0x1,%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xd53(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <enumerate+0xe6>
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x10(%rbp),%rdi
call   1090 <sqlite3_close@plt>
mov    0x2cc4(%rip),%rcx
cmp    (%rcx),%rax
je     136e <enumerate+0x1ce>
mov    0x2ca4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xd0c(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enumerate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e26(%rip),%r13
cmp    0x0(%r13),%rax
jne    12ac <enumerate+0x10c>
mov    0x10(%rsp),%rdi
lea    0xe30(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
cmp    0x0(%r13),%rax
jne    12c8 <enumerate+0x128>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2dc3(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1283 <enumerate+0xe3>
lea    0xe42(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
call   1050 <sqlite3_column_int@plt>
mov    %rax,%r12
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
call   1050 <sqlite3_column_int@plt>
mov    $0xffffffffffffffff,%r8
mov    %ebx,%ecx
shl    %cl,%r8
not    %r8
sub    %rax,%r8
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_step@plt>
cmp    0x0(%rbp),%rax
je     1220 <enumerate+0x80>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    0x10(%rsp),%rdi
call   1090 <sqlite3_close@plt>
cmp    0x0(%r13),%rax
jne    12e4 <enumerate+0x144>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d25(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd3a(%rip),%rsi
jmp    12fe <enumerate+0x15e>
mov    0x2d09(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd5b(%rip),%rsi
jmp    12fe <enumerate+0x15e>
mov    0x2ced(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd69(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [53 x i8] c"SELECT zoom_level, tile_column, tile_row from tiles;\00"
@.str.2 = [23 x i8] c"%s: select failed: %s\0A\00"
@SQLITE_ROW = global i64 0
@.str.3 = [19 x i8] c"%s %lld %lld %lld\0A\00"
@.str.4 = [34 x i8] c"%s: could not close database: %s\0A\00"
define void @enumerate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i64 @sqlite3_open(i8* %9, i32** %3)
%11 = load i64, i64* @SQLITE_OK
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = load i32*, i32** %3
%17 = call i8* @sqlite3_errmsg(i32* %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %1
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8** %4
%22 = load i32*, i32** %3
%23 = load i8*, i8** %4
%24 = call i64 @sqlite3_prepare_v2(i32* %22, i8* %23, i32 -1, i32** %5, i32* null)
%25 = load i64, i64* @SQLITE_OK
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %2
%30 = load i32*, i32** %3
%31 = call i8* @sqlite3_errmsg(i32* %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %21
br label %36
36: ; preds = %41, %35
%37 = load i32*, i32** %5
%38 = call i64 @sqlite3_step(i32* %37)
%39 = load i64, i64* @SQLITE_ROW
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %58
41: ; preds = %36
%42 = load i32*, i32** %5
%43 = call i64 @sqlite3_column_int(i32* %42, i32 0)
store i64 %43, i64* %6
%44 = load i32*, i32** %5
%45 = call i64 @sqlite3_column_int(i32* %44, i32 1)
store i64 %45, i64* %7
%46 = load i32*, i32** %5
%47 = call i64 @sqlite3_column_int(i32* %46, i32 2)
store i64 %47, i64* %8
%48 = load i64, i64* %6
%49 = shl i64 1, %48
%50 = sub nsw i64 %49, 1
%51 = load i64, i64* %8
%52 = sub nsw i64 %50, %51
store i64 %52, i64* %8
%53 = load i8*, i8** %2
%54 = load i64, i64* %6
%55 = load i64, i64* %7
%56 = load i64, i64* %8
%57 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %53, i64 %54, i64 %55, i64 %56)
br label %36
58: ; preds = %36
%59 = load i32*, i32** %5
%60 = call i32 @sqlite3_finalize(i32* %59)
%61 = load i32*, i32** %3
%62 = call i64 @sqlite3_close(i32* %61)
%63 = load i64, i64* @SQLITE_OK
%64 = icmp ne i64 %62, %63
br i1 %64, label %65, label %73
65: ; preds = %58
%66 = load i32, i32* @stderr
%67 = load i8*, i8** %2
%68 = load i32*, i32** %3
%69 = call i8* @sqlite3_errmsg(i32* %68)
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %67, i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %58
ret void
}

LLVM IR (-O2):
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str = [8 x i8] c"%s: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [53 x i8] c"SELECT zoom_level, tile_column, tile_row from tiles;\00"
@.str.2 = [23 x i8] c"%s: select failed: %s\0A\00"
@SQLITE_ROW = global i64 0
@.str.3 = [19 x i8] c"%s %lld %lld %lld\0A\00"
@.str.4 = [34 x i8] c"%s: could not close database: %s\0A\00"
define void @enumerate(i8* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = bitcast i32** %2 to i8*
%5 = call i64 @sqlite3_open(i8* %0, i32** %2)
%6 = load i64, i64* @SQLITE_OK
%7 = icmp eq i64 %5, %6
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32*, i32** %2
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = bitcast i32** %3 to i8*
%17 = load i32*, i32** %2
%18 = call i64 @sqlite3_prepare_v2(i32* %17, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 -1, i32** %3, i32* null)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32*, i32** %3
%23 = call i64 @sqlite3_step(i32* %22)
%24 = load i64, i64* @SQLITE_ROW
%25 = icmp eq i64 %23, %24
br i1 %25, label %33, label %48
26: ; preds = %15
%27 = load i32, i32* @stderr
%28 = load i32*, i32** %2
%29 = call i8* @sqlite3_errmsg(i32* %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %21, %33
%34 = load i32*, i32** %3
%35 = call i64 @sqlite3_column_int(i32* %34, i32 0)
%36 = load i32*, i32** %3
%37 = call i64 @sqlite3_column_int(i32* %36, i32 1)
%38 = load i32*, i32** %3
%39 = call i64 @sqlite3_column_int(i32* %38, i32 2)
%40 = shl nsw i64 -1, %35
%41 = xor i64 %40, -1
%42 = sub nsw i64 %41, %39
%43 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0, i64 %35, i64 %37, i64 %42)
%44 = load i32*, i32** %3
%45 = call i64 @sqlite3_step(i32* %44)
%46 = load i64, i64* @SQLITE_ROW
%47 = icmp eq i64 %45, %46
br i1 %47, label %33, label %48
48: ; preds = %33, %21
%49 = load i32*, i32** %3
%50 = call i32 @sqlite3_finalize(i32* %49)
%51 = load i32*, i32** %2
%52 = call i64 @sqlite3_close(i32* %51)
%53 = load i64, i64* @SQLITE_OK
%54 = icmp eq i64 %52, %53
br i1 %54, label %62, label %55
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = load i32*, i32** %2
%58 = call i8* @sqlite3_errmsg(i32* %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %48
ret void
}