#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 /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ print_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                                     int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_clear_bindings(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
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 /*<<< orphan*/ sqlite3_reset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  sqlite3 *db;
  sqlite3_stmt *stmt_q;
  int rc;
  rc = sqlite3_open("lab1.sql", &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return (1);
  }
  char *sql_qry =
      "WITH RECURSIVE reached(destination_airport_ID) AS(select "
      "destination_airport_ID from routes where source_airport = ? UNION "
      "select r.destination_airport_ID from reached re, routes r where "
      "re.destination_airport_ID = r.source_airport_ID) select "
      "source_airport_ID from routes except select * from reached;";
  rc = sqlite3_prepare_v2(db, sql_qry, -1, &stmt_q, 0);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Preparation failed: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return 1;
  }
  char input_id[4];
  printf("enter id: ");
  scanf("%s", input_id);
  sqlite3_bind_text(stmt_q, 1, input_id, -1, SQLITE_STATIC);
  print_result(stmt_q);
  sqlite3_reset(stmt_q);
  sqlite3_clear_bindings(stmt_q);
  sqlite3_finalize(stmt_q);
  sqlite3_close(db);
  return 0;
}


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    0xe23(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     122f <main+0x6f>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdf4(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1315 <main+0x155>
lea    0xdec(%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   10e0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%eax
je     12a4 <main+0xe4>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xec7(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1315 <main+0x155>
lea    0xebe(%rip),%rdi
call   1050 <printf@plt>
lea    -0x34(%rbp),%rsi
lea    0xeb9(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x34(%rbp),%rdx
mov    0x2d01(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   10b0 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
call   1060 <print_result@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sqlite3_reset@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <sqlite3_clear_bindings@plt>
mov    -0x20(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe32(%rip),%rdi
mov    %rsp,%rsi
call   1040 <sqlite3_open@plt>
test   %eax,%eax
je     11f8 <main+0x38>
mov    0x2df7(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xe16(%rip),%rsi
jmp    12af <main+0xef>
mov    (%rsp),%rdi
lea    0xe1f(%rip),%rsi
lea    0x8(%rsp),%rcx
xor    %ebx,%ebx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10e0 <sqlite3_prepare_v2@plt>
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%eax
jne    1296 <main+0xd6>
lea    0xf40(%rip),%rdi
call   1050 <printf@plt>
lea    0xf3f(%rip),%rdi
lea    0x14(%rsp),%r14
mov    %r14,%rsi
call   10a0 <scanf@plt>
mov    0x8(%rsp),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
call   10b0 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
call   1060 <print_result@plt>
mov    0x8(%rsp),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x8(%rsp),%rdi
call   10c0 <sqlite3_clear_bindings@plt>
mov    0x8(%rsp),%rdi
call   10d0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
jmp    12c7 <main+0x107>
mov    0x2d3b(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xea2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"lab1.sql\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [303 x i8] c"WITH RECURSIVE reached(destination_airport_ID) AS(select destination_airport_ID from routes where source_airport = ? UNION select r.destination_airport_ID from reached re, routes r where re.destination_airport_ID = r.source_airport_ID) select source_airport_ID from routes except select * from reached;\00"
@SQLITE_OK = global i32 0
@.str.3 = [24 x i8] c"Preparation failed: %s\0A\00"
@.str.4 = [11 x i8] c"enter id: \00"
@.str.5 = [3 x i8] c"%s\00"
@SQLITE_STATIC = global i32 0
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 [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 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 %53
21: ; preds = %2
store i8* getelementptr inbounds ([303 x i8], [303 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 %53
35: ; preds = %21
%36 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %7
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%41 = load i32, i32* @SQLITE_STATIC
%42 = call i32 @sqlite3_bind_text(i32* %39, i32 1, i8* %40, i32 -1, i32 %41)
%43 = load i32*, i32** %7
%44 = call i32 @print_result(i32* %43)
%45 = load i32*, i32** %7
%46 = call i32 @sqlite3_reset(i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @sqlite3_clear_bindings(i32* %47)
%49 = load i32*, i32** %7
%50 = call i32 @sqlite3_finalize(i32* %49)
%51 = load i32*, i32** %6
%52 = call i32 @sqlite3_close(i32* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %35, %28, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [9 x i8] c"lab1.sql\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [303 x i8] c"WITH RECURSIVE reached(destination_airport_ID) AS(select destination_airport_ID from routes where source_airport = ? UNION select r.destination_airport_ID from reached re, routes r where re.destination_airport_ID = r.source_airport_ID) select source_airport_ID from routes except select * from reached;\00"
@SQLITE_OK = global i32 0
@.str.3 = [24 x i8] c"Preparation failed: %s\0A\00"
@.str.4 = [11 x i8] c"enter id: \00"
@.str.5 = [3 x i8] c"%s\00"
@SQLITE_STATIC = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [4 x i8]
%6 = bitcast i32** %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32*, i32** %3
%13 = call i8* @sqlite3_errmsg(i32* %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %3
%16 = call i32 @sqlite3_close(i32* %15)
br label %46
17: ; preds = %2
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_prepare_v2(i32* %18, i8* getelementptr inbounds ([303 x i8], [303 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %4, i32 0)
%20 = load i32, i32* @SQLITE_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %29, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i32*, i32** %3
%25 = call i8* @sqlite3_errmsg(i32* %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %3
%28 = call i32 @sqlite3_close(i32* %27)
br label %46
29: ; preds = %17
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%33 = load i32*, i32** %4
%34 = load i32, i32* @SQLITE_STATIC
%35 = call i32 @sqlite3_bind_text(i32* %33, i32 1, i8* %30, i32 -1, i32 %34)
%36 = load i32*, i32** %4
%37 = call i32 @print_result(i32* %36)
%38 = load i32*, i32** %4
%39 = call i32 @sqlite3_reset(i32* %38)
%40 = load i32*, i32** %4
%41 = call i32 @sqlite3_clear_bindings(i32* %40)
%42 = load i32*, i32** %4
%43 = call i32 @sqlite3_finalize(i32* %42)
%44 = load i32*, i32** %3
%45 = call i32 @sqlite3_close(i32* %44)
br label %46
46: ; preds = %22, %29, %10
%47 = phi i32 [ 1, %10 ], [ 1, %22 ], [ 0, %29 ]
ret i32 %47
}