#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 M_PI;
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ SQLITE_STATIC;
double acos(int);
int cos(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int sin(double);
int /*<<< orphan*/ sqlite3_bind_double(int /*<<< orphan*/ *, int, double);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *,
                                     int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_count(int /*<<< orphan*/ *);
double sqlite3_column_double(int /*<<< orphan*/ *, int);
char *sqlite3_column_text(int /*<<< orphan*/ *, int);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ 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_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  sqlite3 *db;
  sqlite3_stmt *stmt;
  sqlite3_stmt *tempstmt;
  sqlite3_stmt *selstmt;
  double lat1, lng1, lat2, lng2;
  char type[30];
  int rc;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <database file>\n", argv[0]);
    return (1);
  }
  rc = sqlite3_open(argv[1], &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return (1);
  }
  char *sql_stmt = "select distinct r.Source_airport, a.Latitude, a.Longitude, "
                   "r.Destination_airport, a2.Latitude, a2.Longitude, "
                   "r.Airline, r.Equipment "
                   "from airports a, airports a2, routes r "
                   "where r.Source_airport = a.IATA_FAA and "
                   "r.Destination_airport = a2.IATA_FAA;";
  char *temp_stmt = "CREATE TEMPORARY TABLE dist(Type TEXT, Distance REAL);";
  sqlite3_exec(db, temp_stmt, 0, 0, 0);
  rc = sqlite3_prepare_v2(db, sql_stmt, -1, &stmt, 0);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Preparation failed: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return 1;
  }
  while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    lat1 = sqlite3_column_double(stmt, 1);
    lng1 = sqlite3_column_double(stmt, 2);
    lat2 = sqlite3_column_double(stmt, 4);
    lng2 = sqlite3_column_double(stmt, 5);
    strcpy(type, sqlite3_column_text(stmt, 7));
    double rlat1 = lat1 * (M_PI / 180);
    double rlat2 = lat2 * (M_PI / 180);
    double rlng1 = lng1 * (M_PI / 180);
    double rlng2 = lng2 * (M_PI / 180);
    double dlat = rlat2 - rlat1;
    double dlng = rlng2 - rlng1;
    double thtm = ((rlat1 + rlat2) / 2);
    double dist = ((6371.009) * acos((sin(rlat1) * sin(rlat2)) +
                                     (cos(rlat1) * cos(rlat1) * cos(dlng))));
    char *insert_stmt = "INSERT INTO dist(Type, Distance) VALUES (?, ?)";
    rc = sqlite3_prepare_v2(db, insert_stmt, -1, &tempstmt, NULL);
    if (rc != SQLITE_OK) {
      fprintf(stderr, "Preparation failed: %s\n", sqlite3_errmsg(db));
      sqlite3_close(db);
      return 1;
    }
    sqlite3_bind_text(tempstmt, 1, type, strlen(type), SQLITE_STATIC);
    sqlite3_bind_double(tempstmt, 2, dist);
    rc = sqlite3_step(tempstmt);
    sqlite3_finalize(tempstmt);
  }
  char *final_sql = "select distinct Type "
                    "from dist "
                    "where Distance > 10000 "
                    "order by Type;";
  rc = sqlite3_prepare_v2(db, final_sql, -1, &stmt, 0);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Preparation failed: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return 1;
  }
  while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
    int col;
    for (col = 0; col < sqlite3_column_count(stmt) - 1; col++) {
      printf("%s|", sqlite3_column_text(stmt, col));
    }
    printf("%s", sqlite3_column_text(stmt, col));
    printf("\n");
  }
  sqlite3_finalize(stmt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     127b <main+0x4b>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda6(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17df <main+0x5af>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <sqlite3_open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     12db <main+0xab>
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe0(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0xe0(%rbp),%edi
mov    %rax,%rdx
lea    0xd6a(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    17df <main+0x5af>
lea    0xd62(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xe4f(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x88(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <sqlite3_exec@plt>
mov    -0x18(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1150 <sqlite3_prepare_v2@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2cab(%rip),%rcx
cmp    (%rcx),%eax
je     137f <main+0x14f>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0xe4(%rbp),%edi
mov    %rax,%rdx
lea    0xe0e(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    17df <main+0x5af>
jmp    1384 <main+0x154>
mov    -0x20(%rbp),%rdi
call   10b0 <sqlite3_step@plt>
mov    %eax,-0x74(%rbp)
mov    0x2c29(%rip),%rcx
cmp    (%rcx),%eax
jne    1693 <main+0x463>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1090 <sqlite3_column_double@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1090 <sqlite3_column_double@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1090 <sqlite3_column_double@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1090 <sqlite3_column_double@plt>
movsd  %xmm0,-0x50(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x7,%esi
call   1110 <sqlite3_column_text@plt>
mov    -0x100(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
movsd  -0x38(%rbp),%xmm0
mov    0x2bc9(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x48(%rbp),%xmm0
mov    0x2ba3(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
mov    0x2b7d(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
mov    0x2b57(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
subsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
subsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
addsd  -0x98(%rbp),%xmm0
ff
movsd  0xb15(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
call   10d0 <sin@plt>
mov    %eax,-0xf4(%rbp)
movsd  -0x98(%rbp),%xmm0
ff
call   10d0 <sin@plt>
mov    %eax,%ecx
mov    -0xf4(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0xec(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
call   1120 <cos@plt>
mov    %eax,-0xf0(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
call   1120 <cos@plt>
mov    %eax,%ecx
mov    -0xf0(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0xe8(%rbp)
movsd  -0xb8(%rbp),%xmm0
ff
call   1120 <cos@plt>
mov    -0xec(%rbp),%edi
mov    %eax,%ecx
mov    -0xe8(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1080 <acos@plt>
movaps %xmm0,%xmm1
movsd  0xa6f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
lea    0xbe7(%rip),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xd0(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1150 <sqlite3_prepare_v2@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2a0a(%rip),%rcx
cmp    (%rcx),%eax
je     1620 <main+0x3f0>
mov    0x29eb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x104(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0x104(%rbp),%edi
mov    %rax,%rdx
lea    0xb6d(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    17df <main+0x5af>
mov    -0x28(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x110(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x118(%rbp),%rdi
mov    -0x110(%rbp),%rdx
mov    %eax,%ecx
mov    0x2972(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
call   1130 <sqlite3_bind_text@plt>
mov    -0x28(%rbp),%rdi
movsd  -0xc8(%rbp),%xmm0
ff
mov    $0x2,%esi
call   1100 <sqlite3_bind_double@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <sqlite3_step@plt>
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%rdi
call   1140 <sqlite3_finalize@plt>
jmp    1384 <main+0x154>
lea    0xb20(%rip),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1150 <sqlite3_prepare_v2@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2914(%rip),%rcx
cmp    (%rcx),%eax
je     1716 <main+0x4e6>
mov    0x28f5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0x11c(%rbp),%edi
mov    %rax,%rdx
lea    0xa77(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10e0 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    17df <main+0x5af>
jmp    171b <main+0x4eb>
mov    -0x20(%rbp),%rdi
call   10b0 <sqlite3_step@plt>
mov    %eax,-0x74(%rbp)
mov    0x2892(%rip),%rcx
cmp    (%rcx),%eax
jne    17cf <main+0x59f>
movl   $0x0,-0xdc(%rbp)
mov    -0xdc(%rbp),%eax
mov    %eax,-0x120(%rbp)
mov    -0x20(%rbp),%rdi
call   10f0 <sqlite3_column_count@plt>
mov    %eax,%ecx
mov    -0x120(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    179c <main+0x56c>
mov    -0x20(%rbp),%rdi
mov    -0xdc(%rbp),%esi
call   1110 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xa7e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xdc(%rbp)
jmp    1740 <main+0x510>
mov    -0x20(%rbp),%rdi
mov    -0xdc(%rbp),%esi
call   1110 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xa4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0x866(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    171b <main+0x4eb>
mov    -0x20(%rbp),%rdi
call   1140 <sqlite3_finalize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jne    1284 <main+0x44>
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
call   1060 <sqlite3_open@plt>
test   %eax,%eax
je     12a1 <main+0x61>
mov    0x2d64(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   10b0 <sqlite3_errmsg@plt>
lea    0xda4(%rip),%rsi
jmp    15b9 <main+0x379>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd71(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    15cd <main+0x38d>
mov    0x10(%rsp),%rdi
lea    0xe87(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <sqlite3_exec@plt>
mov    0x10(%rsp),%rdi
lea    0xd77(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1160 <sqlite3_prepare_v2@plt>
mov    0x2d02(%rip),%r14
cmp    (%r14),%eax
jne    159f <main+0x35f>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
mov    0x2cc8(%rip),%r13
cmp    0x0(%r13),%eax
jne    14cd <main+0x28d>
lea    0x40(%rsp),%r12
lea    0x20(%rsp),%r15
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
call   10a0 <sqlite3_column_double@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
call   10a0 <sqlite3_column_double@plt>
movsd  %xmm0,0x38(%rsp)
mov    0x8(%rsp),%rdi
mov    $0x4,%esi
call   10a0 <sqlite3_column_double@plt>
movsd  %xmm0,0x30(%rsp)
mov    0x8(%rsp),%rdi
mov    $0x5,%esi
call   10a0 <sqlite3_column_double@plt>
movsd  %xmm0,0x28(%rsp)
mov    0x8(%rsp),%rdi
mov    $0x7,%esi
call   1120 <sqlite3_column_text@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    0x2c63(%rip),%rax
movslq (%rax),%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x7,%ecx
add    %eax,%ecx
cvtsi2sd %ecx,%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x30(%rsp),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x30(%rsp)
movsd  0x38(%rsp),%xmm3
mulsd  %xmm1,%xmm3
movsd  0x28(%rsp),%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm3,%xmm2
movsd  %xmm2,0x28(%rsp)
call   10e0 <sin@plt>
mov    %eax,%ebp
movsd  0x30(%rsp),%xmm0
call   10e0 <sin@plt>
imul   %eax,%ebp
movsd  0x18(%rsp),%xmm0
call   1130 <cos@plt>
mov    %eax,%ebx
movsd  0x18(%rsp),%xmm0
call   1130 <cos@plt>
imul   %eax,%ebx
movsd  0x28(%rsp),%xmm0
call   1130 <cos@plt>
imul   %eax,%ebx
add    %ebp,%ebx
mov    %ebx,%edi
call   1090 <acos@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rdi
lea    0xd49(%rip),%rsi
mov    $0xffffffff,%edx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1160 <sqlite3_prepare_v2@plt>
cmp    (%r14),%eax
jne    159f <main+0x35f>
movsd  0x18(%rsp),%xmm0
mulsd  0xb9f(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    0x20(%rsp),%rbx
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    0x2b4d(%rip),%rcx
mov    (%rcx),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %eax,%ecx
call   1140 <sqlite3_bind_text@plt>
mov    0x20(%rsp),%rdi
mov    $0x2,%esi
movsd  0x18(%rsp),%xmm0
call   1110 <sqlite3_bind_double@plt>
mov    0x20(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
mov    0x20(%rsp),%rdi
call   1150 <sqlite3_finalize@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
cmp    0x0(%r13),%eax
je     1310 <main+0xd0>
mov    0x10(%rsp),%rdi
lea    0xcd9(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1160 <sqlite3_prepare_v2@plt>
cmp    (%r14),%eax
jne    159f <main+0x35f>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
cmp    0x0(%r13),%eax
jne    15e1 <main+0x3a1>
lea    0xce8(%rip),%rbx
lea    0xce5(%rip),%r14
jmp    1557 <main+0x317>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1120 <sqlite3_column_text@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_step@plt>
cmp    0x0(%r13),%eax
jne    15e1 <main+0x3a1>
mov    0x8(%rsp),%rdi
call   1100 <sqlite3_column_count@plt>
mov    $0x0,%ebp
cmp    $0x2,%eax
jl     1520 <main+0x2e0>
xor    %ebp,%ebp
nopl   (%rax)
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1120 <sqlite3_column_text@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   1100 <sqlite3_column_count@plt>
add    $0xffffffff,%eax
cmp    %eax,%ebp
jl     1570 <main+0x330>
jmp    1520 <main+0x2e0>
mov    0x2a2a(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   10b0 <sqlite3_errmsg@plt>
lea    0xbb2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10d0 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   10f0 <sqlite3_close@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
call   1150 <sqlite3_finalize@plt>
xor    %eax,%eax
jmp    15d2 <main+0x392>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <database file>\0A\00"
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [248 x i8] c"select distinct r.Source_airport, a.Latitude, a.Longitude, r.Destination_airport, a2.Latitude, a2.Longitude, r.Airline, r.Equipment from airports a, airports a2, routes r where r.Source_airport = a.IATA_FAA and r.Destination_airport = a2.IATA_FAA;\00"
@.str.3 = [55 x i8] c"CREATE TEMPORARY TABLE dist(Type TEXT, Distance REAL);\00"
@SQLITE_OK = global i32 0
@.str.4 = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
@M_PI = global i32 0
@.str.5 = [47 x i8] c"INSERT INTO dist(Type, Distance) VALUES (?, ?)\00"
@SQLITE_STATIC = global i32 0
@.str.6 = [69 x i8] c"select distinct Type from dist where Distance > 10000 order by Type;\00"
@.str.7 = [4 x i8] c"%s|\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [2 x i8] c"\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 double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca [30 x i8]
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca i8*
%27 = alloca i8*
%28 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 2
br i1 %30, label %31, label %37
31: ; preds = %2
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %204
37: ; preds = %2
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @sqlite3_open(i8* %40, i32** %6)
store i32 %41, i32* %15
%42 = load i32, i32* %15
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = load i32*, i32** %6
%47 = call i8* @sqlite3_errmsg(i32* %46)
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %6
%50 = call i32 @sqlite3_close(i32* %49)
store i32 1, i32* %3
br label %204
51: ; preds = %37
store i8* getelementptr inbounds ([248 x i8], [248 x i8]* @.str.2, i64 0, i64 0), i8** %16
store i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i8** %17
%52 = load i32*, i32** %6
%53 = load i8*, i8** %17
%54 = call i32 @sqlite3_exec(i32* %52, i8* %53, i32 0, i32 0, i32 0)
%55 = load i32*, i32** %6
%56 = load i8*, i8** %16
%57 = call i32 @sqlite3_prepare_v2(i32* %55, i8* %56, i32 -1, i32** %7, i32* null)
store i32 %57, i32* %15
%58 = load i32, i32* %15
%59 = load i32, i32* @SQLITE_OK
%60 = icmp ne i32 %58, %59
br i1 %60, label %61, label %68
61: ; preds = %51
%62 = load i32, i32* @stderr
%63 = load i32*, i32** %6
%64 = call i8* @sqlite3_errmsg(i32* %63)
%65 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = load i32*, i32** %6
%67 = call i32 @sqlite3_close(i32* %66)
store i32 1, i32* %3
br label %204
68: ; preds = %51
br label %69
69: ; preds = %146, %68
%70 = load i32*, i32** %7
%71 = call i32 @sqlite3_step(i32* %70)
store i32 %71, i32* %15
%72 = load i32, i32* @SQLITE_ROW
%73 = icmp eq i32 %71, %72
br i1 %73, label %74, label %160
74: ; preds = %69
%75 = load i32*, i32** %7
%76 = call double @sqlite3_column_double(i32* %75, i32 1)
store double %76, double* %10
%77 = load i32*, i32** %7
%78 = call double @sqlite3_column_double(i32* %77, i32 2)
store double %78, double* %11
%79 = load i32*, i32** %7
%80 = call double @sqlite3_column_double(i32* %79, i32 4)
store double %80, double* %12
%81 = load i32*, i32** %7
%82 = call double @sqlite3_column_double(i32* %81, i32 5)
store double %82, double* %13
%83 = getelementptr inbounds [30 x i8], [30 x i8]* %14, i64 0, i64 0
%84 = load i32*, i32** %7
%85 = call i8* @sqlite3_column_text(i32* %84, i32 7)
%86 = call i32 @strcpy(i8* %83, i8* %85)
%87 = load double, double* %10
%88 = load i32, i32* @M_PI
%89 = sdiv i32 %88, 180
%90 = sitofp i32 %89 to double
%91 = fmul double %87, %90
store double %91, double* %18
%92 = load double, double* %12
%93 = load i32, i32* @M_PI
%94 = sdiv i32 %93, 180
%95 = sitofp i32 %94 to double
%96 = fmul double %92, %95
store double %96, double* %19
%97 = load double, double* %11
%98 = load i32, i32* @M_PI
%99 = sdiv i32 %98, 180
%100 = sitofp i32 %99 to double
%101 = fmul double %97, %100
store double %101, double* %20
%102 = load double, double* %13
%103 = load i32, i32* @M_PI
%104 = sdiv i32 %103, 180
%105 = sitofp i32 %104 to double
%106 = fmul double %102, %105
store double %106, double* %21
%107 = load double, double* %19
%108 = load double, double* %18
%109 = fsub double %107, %108
store double %109, double* %22
%110 = load double, double* %21
%111 = load double, double* %20
%112 = fsub double %110, %111
store double %112, double* %23
%113 = load double, double* %18
%114 = load double, double* %19
%115 = fadd double %113, %114
%116 = fdiv double %115, 2.000000e+00
store double %116, double* %24
%117 = load double, double* %18
%118 = call i32 @sin(double %117)
%119 = load double, double* %19
%120 = call i32 @sin(double %119)
%121 = mul nsw i32 %118, %120
%122 = load double, double* %18
%123 = call i32 @cos(double %122)
%124 = load double, double* %18
%125 = call i32 @cos(double %124)
%126 = mul nsw i32 %123, %125
%127 = load double, double* %23
%128 = call i32 @cos(double %127)
%129 = mul nsw i32 %126, %128
%130 = add nsw i32 %121, %129
%131 = call double @acos(i32 %130)
%132 = fmul double 0x40B8E3024DD2F1AA, %131
store double %132, double* %25
store i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8** %26
%133 = load i32*, i32** %6
%134 = load i8*, i8** %26
%135 = call i32 @sqlite3_prepare_v2(i32* %133, i8* %134, i32 -1, i32** %8, i32* null)
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 %146
139: ; preds = %74
%140 = load i32, i32* @stderr
%141 = load i32*, i32** %6
%142 = call i8* @sqlite3_errmsg(i32* %141)
%143 = call i32 @fprintf(i32 %140, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %142)
%144 = load i32*, i32** %6
%145 = call i32 @sqlite3_close(i32* %144)
store i32 1, i32* %3
br label %204
146: ; preds = %74
%147 = load i32*, i32** %8
%148 = getelementptr inbounds [30 x i8], [30 x i8]* %14, i64 0, i64 0
%149 = getelementptr inbounds [30 x i8], [30 x i8]* %14, i64 0, i64 0
%150 = call i32 @strlen(i8* %149)
%151 = load i32, i32* @SQLITE_STATIC
%152 = call i32 @sqlite3_bind_text(i32* %147, i32 1, i8* %148, i32 %150, i32 %151)
%153 = load i32*, i32** %8
%154 = load double, double* %25
%155 = call i32 @sqlite3_bind_double(i32* %153, i32 2, double %154)
%156 = load i32*, i32** %8
%157 = call i32 @sqlite3_step(i32* %156)
store i32 %157, i32* %15
%158 = load i32*, i32** %8
%159 = call i32 @sqlite3_finalize(i32* %158)
br label %69
160: ; preds = %69
store i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i8** %27
%161 = load i32*, i32** %6
%162 = load i8*, i8** %27
%163 = call i32 @sqlite3_prepare_v2(i32* %161, i8* %162, i32 -1, i32** %7, i32* null)
store i32 %163, i32* %15
%164 = load i32, i32* %15
%165 = load i32, i32* @SQLITE_OK
%166 = icmp ne i32 %164, %165
br i1 %166, label %167, label %174
167: ; preds = %160
%168 = load i32, i32* @stderr
%169 = load i32*, i32** %6
%170 = call i8* @sqlite3_errmsg(i32* %169)
%171 = call i32 @fprintf(i32 %168, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %170)
%172 = load i32*, i32** %6
%173 = call i32 @sqlite3_close(i32* %172)
store i32 1, i32* %3
br label %204
174: ; preds = %160
br label %175
175: ; preds = %195, %174
%176 = load i32*, i32** %7
%177 = call i32 @sqlite3_step(i32* %176)
store i32 %177, i32* %15
%178 = load i32, i32* @SQLITE_ROW
%179 = icmp eq i32 %177, %178
br i1 %179, label %180, label %201
180: ; preds = %175
store i32 0, i32* %28
br label %181
181: ; preds = %192, %180
%182 = load i32, i32* %28
%183 = load i32*, i32** %7
%184 = call i32 @sqlite3_column_count(i32* %183)
%185 = sub nsw i32 %184, 1
%186 = icmp slt i32 %182, %185
br i1 %186, label %187, label %195
187: ; preds = %181
%188 = load i32*, i32** %7
%189 = load i32, i32* %28
%190 = call i8* @sqlite3_column_text(i32* %188, i32 %189)
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %190)
br label %192
192: ; preds = %187
%193 = load i32, i32* %28
%194 = add nsw i32 %193, 1
store i32 %194, i32* %28
br label %181
195: ; preds = %181
%196 = load i32*, i32** %7
%197 = load i32, i32* %28
%198 = call i8* @sqlite3_column_text(i32* %196, i32 %197)
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %198)
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %175
201: ; preds = %175
%202 = load i32*, i32** %7
%203 = call i32 @sqlite3_finalize(i32* %202)
store i32 0, i32* %3
br label %204
204: ; preds = %201, %167, %139, %61, %44, %31
%205 = load i32, i32* %3
ret i32 %205
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s <database file>\0A\00"
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [248 x i8] c"select distinct r.Source_airport, a.Latitude, a.Longitude, r.Destination_airport, a2.Latitude, a2.Longitude, r.Airline, r.Equipment from airports a, airports a2, routes r where r.Source_airport = a.IATA_FAA and r.Destination_airport = a2.IATA_FAA;\00"
@.str.3 = [55 x i8] c"CREATE TEMPORARY TABLE dist(Type TEXT, Distance REAL);\00"
@SQLITE_OK = global i32 0
@.str.4 = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
@M_PI = global i32 0
@.str.5 = [47 x i8] c"INSERT INTO dist(Type, Distance) VALUES (?, ?)\00"
@SQLITE_STATIC = global i32 0
@.str.6 = [69 x i8] c"select distinct Type from dist where Distance > 10000 order by Type;\00"
@.str.7 = [4 x i8] c"%s|\00"
@.str.8 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [30 x i8]
%7 = bitcast i32** %3 to i8*
%8 = bitcast i32** %4 to i8*
%9 = bitcast i32** %5 to i8*
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %148
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sqlite3_open(i8* %18, i32** %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i32*, i32** %3
%24 = call i8* @sqlite3_errmsg(i32* %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %3
%27 = call i32 @sqlite3_close(i32* %26)
br label %148
28: ; preds = %16
%29 = load i32*, i32** %3
%30 = call i32 @sqlite3_exec(i32* %29, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0, i32 0)
%31 = load i32*, i32** %3
%32 = call i32 @sqlite3_prepare_v2(i32* %31, i8* getelementptr inbounds ([248 x i8], [248 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%33 = load i32, i32* @SQLITE_OK
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32*, i32** %4
%37 = call i32 @sqlite3_step(i32* %36)
%38 = load i32, i32* @SQLITE_ROW
%39 = icmp eq i32 %37, %38
br i1 %39, label %47, label %104
40: ; preds = %28
%41 = load i32, i32* @stderr
%42 = load i32*, i32** %3
%43 = call i8* @sqlite3_errmsg(i32* %42)
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %3
%46 = call i32 @sqlite3_close(i32* %45)
br label %148
47: ; preds = %35, %88
%48 = load i32*, i32** %4
%49 = call double @sqlite3_column_double(i32* %48, i32 1)
%50 = load i32*, i32** %4
%51 = call double @sqlite3_column_double(i32* %50, i32 2)
%52 = load i32*, i32** %4
%53 = call double @sqlite3_column_double(i32* %52, i32 4)
%54 = load i32*, i32** %4
%55 = call double @sqlite3_column_double(i32* %54, i32 5)
%56 = load i32*, i32** %4
%57 = call i8* @sqlite3_column_text(i32* %56, i32 7)
%58 = call i32 @strcpy(i8* %10, i8* %57)
%59 = load i32, i32* @M_PI
%60 = sdiv i32 %59, 180
%61 = sitofp i32 %60 to double
%62 = fmul double %49, %61
%63 = fmul double %53, %61
%64 = fmul double %51, %61
%65 = fmul double %55, %61
%66 = fsub double %65, %64
%67 = call i32 @sin(double %62)
%68 = call i32 @sin(double %63)
%69 = mul nsw i32 %68, %67
%70 = call i32 @cos(double %62)
%71 = call i32 @cos(double %62)
%72 = mul nsw i32 %71, %70
%73 = call i32 @cos(double %66)
%74 = mul nsw i32 %72, %73
%75 = add nsw i32 %74, %69
%76 = call double @acos(i32 %75)
%77 = load i32*, i32** %3
%78 = call i32 @sqlite3_prepare_v2(i32* %77, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 -1, i32** %5, i32* null)
%79 = load i32, i32* @SQLITE_OK
%80 = icmp eq i32 %78, %79
br i1 %80, label %88, label %81
81: ; preds = %47
%82 = load i32, i32* @stderr
%83 = load i32*, i32** %3
%84 = call i8* @sqlite3_errmsg(i32* %83)
%85 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %84)
%86 = load i32*, i32** %3
%87 = call i32 @sqlite3_close(i32* %86)
br label %148
88: ; preds = %47
%89 = fmul double %76, 0x40B8E3024DD2F1AA
%90 = load i32*, i32** %5
%91 = call i32 @strlen(i8* %10)
%92 = load i32, i32* @SQLITE_STATIC
%93 = call i32 @sqlite3_bind_text(i32* %90, i32 1, i8* %10, i32 %91, i32 %92)
%94 = load i32*, i32** %5
%95 = call i32 @sqlite3_bind_double(i32* %94, i32 2, double %89)
%96 = load i32*, i32** %5
%97 = call i32 @sqlite3_step(i32* %96)
%98 = load i32*, i32** %5
%99 = call i32 @sqlite3_finalize(i32* %98)
%100 = load i32*, i32** %4
%101 = call i32 @sqlite3_step(i32* %100)
%102 = load i32, i32* @SQLITE_ROW
%103 = icmp eq i32 %101, %102
br i1 %103, label %47, label %104
104: ; preds = %88, %35
%105 = load i32*, i32** %3
%106 = call i32 @sqlite3_prepare_v2(i32* %105, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%107 = load i32, i32* @SQLITE_OK
%108 = icmp eq i32 %106, %107
br i1 %108, label %109, label %114
109: ; preds = %104
%110 = load i32*, i32** %4
%111 = call i32 @sqlite3_step(i32* %110)
%112 = load i32, i32* @SQLITE_ROW
%113 = icmp eq i32 %111, %112
br i1 %113, label %121, label %145
114: ; preds = %104
%115 = load i32, i32* @stderr
%116 = load i32*, i32** %3
%117 = call i8* @sqlite3_errmsg(i32* %116)
%118 = call i32 @fprintf(i32 %115, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %117)
%119 = load i32*, i32** %3
%120 = call i32 @sqlite3_close(i32* %119)
br label %148
121: ; preds = %109, %135
%122 = load i32*, i32** %4
%123 = call i32 @sqlite3_column_count(i32* %122)
%124 = icmp sgt i32 %123, 1
br i1 %124, label %125, label %135
125: ; preds = %121, %125
%126 = phi i32 [ %130, %125 ], [ 0, %121 ]
%127 = load i32*, i32** %4
%128 = call i8* @sqlite3_column_text(i32* %127, i32 %126)
%129 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %128)
%130 = add nuw nsw i32 %126, 1
%131 = load i32*, i32** %4
%132 = call i32 @sqlite3_column_count(i32* %131)
%133 = add nsw i32 %132, -1
%134 = icmp slt i32 %130, %133
br i1 %134, label %125, label %135
135: ; preds = %125, %121
%136 = phi i32 [ 0, %121 ], [ %130, %125 ]
%137 = load i32*, i32** %4
%138 = call i8* @sqlite3_column_text(i32* %137, i32 %136)
%139 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %138)
%140 = call i32 @putchar(i32 10)
%141 = load i32*, i32** %4
%142 = call i32 @sqlite3_step(i32* %141)
%143 = load i32, i32* @SQLITE_ROW
%144 = icmp eq i32 %142, %143
br i1 %144, label %121, label %145
145: ; preds = %135, %109
%146 = load i32*, i32** %4
%147 = call i32 @sqlite3_finalize(i32* %146)
br label %148
148: ; preds = %81, %40, %145, %114, %21, %12
%149 = phi i32 [ 1, %12 ], [ 1, %21 ], [ 1, %40 ], [ 1, %114 ], [ 0, %145 ], [ 1, %81 ]
ret i32 %149
}