#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_ROW;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
scalar_t__ sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/, 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 create_trip(char *database) {
  int retval;
  sqlite3 *handle;
  retval = sqlite3_open(database, &handle);
  if (retval) {
    printf("Creating Trip: Database connection failed\n");
    return -1;
  }
  char *createquery = "INSERT INTO Trip DEFAULT VALUES";
  retval = sqlite3_exec(handle, createquery, 0, 0, 0);
  if (retval) {
    printf("Create Trip: Creating trip in DB Failed: %d\n", retval);
    return -1;
  }
  int tripid;
  char *selectquery = "SELECT last_insert_rowid() AS tripid";
  sqlite3_stmt *stmt;
  retval = sqlite3_prepare_v2(handle, selectquery, -1, &stmt, 0);
  if (retval) {
    printf("Create Trip: Selecting trip from DB Failed: %d\n", retval);
    return -1;
  }
  retval = sqlite3_step(stmt);
  if (retval != SQLITE_ROW) {
    printf("Create Trip: SQL error whilst reading rows: %d\n", retval);
    return -1;
  }
  tripid = (int)sqlite3_column_int(stmt, 0);
  sqlite3_close(handle);
  return tripid;
}


x86 assembly (clang, -O0):
<create_trip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b0 <create_trip+0x40>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <create_trip+0x131>
lea    0xe74(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11fb <create_trip+0x8b>
mov    -0x14(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <create_trip+0x131>
lea    0xe76(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x40(%rbp),%rcx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1249 <create_trip+0xd9>
mov    -0x14(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <create_trip+0x131>
mov    -0x40(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
je     1284 <create_trip+0x114>
mov    -0x14(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a1 <create_trip+0x131>
mov    -0x40(%rbp),%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_int@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_trip>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
call   1050 <sqlite3_open@plt>
test   %eax,%eax
je     11a7 <create_trip+0x27>
lea    0xf3a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1247 <create_trip+0xc7>
mov    (%rsp),%rdi
lea    0xe4e(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <sqlite3_exec@plt>
test   %eax,%eax
je     11d9 <create_trip+0x59>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1247 <create_trip+0xc7>
mov    (%rsp),%rdi
lea    0xe69(%rip),%rsi
mov    $0xffffffff,%ebx
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
test   %eax,%eax
je     1208 <create_trip+0x88>
lea    0xe6c(%rip),%rdi
jmp    123e <create_trip+0xbe>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    1237 <create_trip+0xb7>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_int@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
call   1090 <sqlite3_close@plt>
jmp    1247 <create_trip+0xc7>
lea    0xe64(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Creating Trip: Database connection failed\0A\00"
@.str.1 = [32 x i8] c"INSERT INTO Trip DEFAULT VALUES\00"
@.str.2 = [45 x i8] c"Create Trip: Creating trip in DB Failed: %d\0A\00"
@.str.3 = [37 x i8] c"SELECT last_insert_rowid() AS tripid\00"
@.str.4 = [48 x i8] c"Create Trip: Selecting trip from DB Failed: %d\0A\00"
@SQLITE_ROW = global i32 0
@.str.5 = [48 x i8] c"Create Trip: SQL error whilst reading rows: %d\0A\00"
define i32 @create_trip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @sqlite3_open(i8* %10, i32** %5)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %50
16: ; preds = %1
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8** %6
%17 = load i32*, i32** %5
%18 = load i8*, i8** %6
%19 = call i32 @sqlite3_exec(i32* %17, i8* %18, i32 0, i32 0, i32 0)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 -1, i32* %2
br label %50
25: ; preds = %16
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8** %8
%26 = load i32*, i32** %5
%27 = load i8*, i8** %8
%28 = call i32 @sqlite3_prepare_v2(i32* %26, i8* %27, i32 -1, i32** %9, i32 0)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %32)
store i32 -1, i32* %2
br label %50
34: ; preds = %25
%35 = load i32*, i32** %9
%36 = call i32 @sqlite3_step(i32* %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = load i32, i32* @SQLITE_ROW
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = load i32, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %41)
store i32 -1, i32* %2
br label %50
43: ; preds = %34
%44 = load i32*, i32** %9
%45 = call i64 @sqlite3_column_int(i32* %44, i32 0)
%46 = trunc i64 %45 to i32
store i32 %46, i32* %7
%47 = load i32*, i32** %5
%48 = call i32 @sqlite3_close(i32* %47)
%49 = load i32, i32* %7
store i32 %49, i32* %2
br label %50
50: ; preds = %43, %40, %31, %22, %14
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"INSERT INTO Trip DEFAULT VALUES\00"
@.str.2 = [45 x i8] c"Create Trip: Creating trip in DB Failed: %d\0A\00"
@.str.3 = [37 x i8] c"SELECT last_insert_rowid() AS tripid\00"
@.str.4 = [48 x i8] c"Create Trip: Selecting trip from DB Failed: %d\0A\00"
@SQLITE_ROW = global i32 0
@.str.5 = [48 x i8] c"Create Trip: SQL error whilst reading rows: %d\0A\00"
@str = [42 x i8] c"Creating Trip: Database connection failed\00"
define i32 @create_trip(i8* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = bitcast i32** %2 to i8*
%5 = call i32 @sqlite3_open(i8* %0, i32** %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %37
9: ; preds = %1
%10 = load i32*, i32** %2
%11 = call i32 @sqlite3_exec(i32* %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %37
15: ; preds = %9
%16 = bitcast i32** %3 to i8*
%17 = load i32*, i32** %2
%18 = call i32 @sqlite3_prepare_v2(i32* %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 -1, i32** %3, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %35
22: ; preds = %15
%23 = load i32*, i32** %3
%24 = call i32 @sqlite3_step(i32* %23)
%25 = load i32, i32* @SQLITE_ROW
%26 = icmp eq i32 %24, %25
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0), i32 %24)
br label %35
29: ; preds = %22
%30 = load i32*, i32** %3
%31 = call i64 @sqlite3_column_int(i32* %30, i32 0)
%32 = trunc i64 %31 to i32
%33 = load i32*, i32** %2
%34 = call i32 @sqlite3_close(i32* %33)
br label %35
35: ; preds = %29, %27, %20
%36 = phi i32 [ -1, %20 ], [ -1, %27 ], [ %32, %29 ]
br label %37
37: ; preds = %13, %35, %7
%38 = phi i32 [ -1, %7 ], [ -1, %13 ], [ %36, %35 ]
ret i32 %38
}