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

/* Forward declarations */

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

/* Variables and functions */
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_count(int /*<<< orphan*/ *);
char *sqlite3_column_text(int /*<<< orphan*/ *, int);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  sqlite3 *db;
  sqlite3_stmt *stmt;
  int rc;
  rc = sqlite3_open("openflights.db", &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return (1);
  }
  char *sql_stmt =
      "select count(a.Airline_ID) from airlines a where a.ICAO = \'\\N' or "
      "a.IATA = \'\\N' or a.Callsign = \'\\N' or a.Country = \'\\N' and "
      "a.Airline_ID in (select distinct r.Airline_ID from routes r, routes r1 "
      "where r.Source_airport_ID = r1.Destination_airport_ID and "
      "r.Destination_airport_ID = r1.Source_airport_ID);";
  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) {
    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);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe43(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     120f <main+0x6f>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xe1a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    132e <main+0x18e>
lea    0xe12(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%eax
je     1284 <main+0xe4>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xeee(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    132e <main+0x18e>
jmp    1289 <main+0xe9>
mov    -0x20(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d34(%rip),%rcx
cmp    (%rcx),%eax
jne    1325 <main+0x185>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_column_count@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12f5 <main+0x155>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ab <main+0x10b>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1289 <main+0xe9>
mov    -0x20(%rbp),%rdi
call   10b0 <sqlite3_finalize@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe3f(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11ee <main+0x3e>
mov    0x2e02(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xe26(%rip),%rsi
jmp    12e9 <main+0x139>
mov    0x10(%rsp),%rdi
lea    0xe2e(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10d0 <sqlite3_prepare_v2@plt>
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
jne    12cf <main+0x11f>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2da4(%rip),%r15
cmp    (%r15),%eax
jne    130d <main+0x15d>
lea    0xf34(%rip),%rbx
lea    0xf31(%rip),%r14
jmp    1286 <main+0xd6>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_step@plt>
cmp    (%r15),%eax
jne    130d <main+0x15d>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_column_count@plt>
mov    $0x0,%ebp
cmp    $0x2,%eax
jl     1250 <main+0xa0>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
call   10b0 <sqlite3_column_text@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_column_count@plt>
add    $0xffffffff,%eax
cmp    %eax,%ebp
jl     12a0 <main+0xf0>
jmp    1250 <main+0xa0>
mov    0x2d02(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xe6f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1090 <sqlite3_close@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_finalize@plt>
xor    %eax,%eax
jmp    1302 <main+0x152>

LLVM IR (-O0):
@.str = [15 x i8] c"openflights.db\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [304 x i8] c"select count(a.Airline_ID) from airlines a where a.ICAO = '\\N' or a.IATA = '\\N' or a.Callsign = '\\N' or a.Country = '\\N' and a.Airline_ID in (select distinct r.Airline_ID from routes r, routes r1 where r.Source_airport_ID = r1.Destination_airport_ID and r.Destination_airport_ID = r1.Source_airport_ID);\00"
@SQLITE_OK = global i32 0
@.str.3 = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.4 = [4 x i8] c"%s|\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [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 i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @sqlite3_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32** %6)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i32*, i32** %6
%17 = call i8* @sqlite3_errmsg(i32* %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32*, i32** %6
%20 = call i32 @sqlite3_close(i32* %19)
store i32 1, i32* %3
br label %65
21: ; preds = %2
store i8* getelementptr inbounds ([304 x i8], [304 x i8]* @.str.2, i64 0, i64 0), i8** %9
%22 = load i32*, i32** %6
%23 = load i8*, i8** %9
%24 = call i32 @sqlite3_prepare_v2(i32* %22, i8* %23, i32 -1, i32** %7, i32 0)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = load i32, i32* @SQLITE_OK
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i32*, i32** %6
%31 = call i8* @sqlite3_errmsg(i32* %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32*, i32** %6
%34 = call i32 @sqlite3_close(i32* %33)
store i32 1, i32* %3
br label %65
35: ; preds = %21
br label %36
36: ; preds = %56, %35
%37 = load i32*, i32** %7
%38 = call i32 @sqlite3_step(i32* %37)
store i32 %38, i32* %8
%39 = load i32, i32* @SQLITE_ROW
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %62
41: ; preds = %36
store i32 0, i32* %10
br label %42
42: ; preds = %53, %41
%43 = load i32, i32* %10
%44 = load i32*, i32** %7
%45 = call i32 @sqlite3_column_count(i32* %44)
%46 = sub nsw i32 %45, 1
%47 = icmp slt i32 %43, %46
br i1 %47, label %48, label %56
48: ; preds = %42
%49 = load i32*, i32** %7
%50 = load i32, i32* %10
%51 = call i8* @sqlite3_column_text(i32* %49, i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %48
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %42
56: ; preds = %42
%57 = load i32*, i32** %7
%58 = load i32, i32* %10
%59 = call i8* @sqlite3_column_text(i32* %57, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %36
62: ; preds = %36
%63 = load i32*, i32** %7
%64 = call i32 @sqlite3_finalize(i32* %63)
br label %65
65: ; preds = %62, %28, %14
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [15 x i8] c"openflights.db\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [304 x i8] c"select count(a.Airline_ID) from airlines a where a.ICAO = '\\N' or a.IATA = '\\N' or a.Callsign = '\\N' or a.Country = '\\N' and a.Airline_ID in (select distinct r.Airline_ID from routes r, routes r1 where r.Source_airport_ID = r1.Destination_airport_ID and r.Destination_airport_ID = r1.Source_airport_ID);\00"
@SQLITE_OK = global i32 0
@.str.3 = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.4 = [4 x i8] c"%s|\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = bitcast i32** %3 to i8*
%6 = bitcast i32** %4 to i8*
%7 = call i32 @sqlite3_open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32** %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32*, i32** %3
%12 = call i8* @sqlite3_errmsg(i32* %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %3
%15 = call i32 @sqlite3_close(i32* %14)
br label %60
16: ; preds = %2
%17 = load i32*, i32** %3
%18 = call i32 @sqlite3_prepare_v2(i32* %17, i8* getelementptr inbounds ([304 x i8], [304 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %4, i32 0)
%19 = load i32, i32* @SQLITE_OK
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32*, i32** %4
%23 = call i32 @sqlite3_step(i32* %22)
%24 = load i32, i32* @SQLITE_ROW
%25 = icmp eq i32 %23, %24
br i1 %25, label %33, label %57
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = load i32*, i32** %3
%29 = call i8* @sqlite3_errmsg(i32* %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load i32*, i32** %3
%32 = call i32 @sqlite3_close(i32* %31)
br label %60
33: ; preds = %21, %47
%34 = load i32*, i32** %4
%35 = call i32 @sqlite3_column_count(i32* %34)
%36 = icmp sgt i32 %35, 1
br i1 %36, label %37, label %47
37: ; preds = %33, %37
%38 = phi i32 [ %42, %37 ], [ 0, %33 ]
%39 = load i32*, i32** %4
%40 = call i8* @sqlite3_column_text(i32* %39, i32 %38)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = add nuw nsw i32 %38, 1
%43 = load i32*, i32** %4
%44 = call i32 @sqlite3_column_count(i32* %43)
%45 = add nsw i32 %44, -1
%46 = icmp slt i32 %42, %45
br i1 %46, label %37, label %47
47: ; preds = %37, %33
%48 = phi i32 [ 0, %33 ], [ %42, %37 ]
%49 = load i32*, i32** %4
%50 = call i8* @sqlite3_column_text(i32* %49, i32 %48)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %50)
%52 = call i32 @putchar(i32 10)
%53 = load i32*, i32** %4
%54 = call i32 @sqlite3_step(i32* %53)
%55 = load i32, i32* @SQLITE_ROW
%56 = icmp eq i32 %54, %55
br i1 %56, label %33, label %57
57: ; preds = %47, %21
%58 = load i32*, i32** %4
%59 = call i32 @sqlite3_finalize(i32* %58)
br label %60
60: ; preds = %26, %57, %9
%61 = phi i32 [ 1, %9 ], [ 1, %26 ], [ 0, %57 ]
ret i32 %61
}