#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*/ *);
char *sqlite3_column_text(int /*<<< orphan*/ *, 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_shutdown();
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int update_db() {
  sqlite3 *sqlite_db = NULL;
  sqlite3_stmt *query = NULL;
  int ret = 0;
  if (SQLITE_OK != (ret = sqlite3_open(":memory:", &sqlite_db))) {
    fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(sqlite_db));
    sqlite3_close(sqlite_db);
    return 1;
  }
  if (SQLITE_OK != (ret = sqlite3_prepare_v2(
                        sqlite_db, "SELECT SQLITE_VERSION()", -1, &query, 0))) {
    fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(sqlite_db));
    sqlite3_close(sqlite_db);
    return 1;
  }
  if (SQLITE_OK !=
      (ret = sqlite3_prepare_v2(sqlite_db, "SELECT TEST", -1, &query, NULL))) {
    printf("Failed to prepare insert: %d, %s\n", ret,
           sqlite3_errmsg(sqlite_db));
    return 1;
  }
  if (SQLITE_ROW != (ret = sqlite3_step(query))) {
    printf("Failed to step: %d, %s\n", ret, sqlite3_errmsg(sqlite_db));
    return 1;
  }
  printf("Value from sqlite: %s", sqlite3_column_text(query, 0));
  if (NULL != query)
    sqlite3_finalize(query);
  if (NULL != sqlite_db)
    sqlite3_close(sqlite_db);
  sqlite3_shutdown();
  return ret;
}


x86 assembly (clang, -O0):
<update_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xe2e(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
mov    %ecx,-0x1c(%rbp)
cmp    %ecx,%eax
je     1227 <update_db+0x87>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdfc(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ad <update_db+0x20d>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xde5(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
mov    %ecx,-0x1c(%rbp)
cmp    %ecx,%eax
je     129d <update_db+0xfd>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdb8(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ad <update_db+0x20d>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xda1(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
mov    %ecx,-0x1c(%rbp)
cmp    %ecx,%eax
je     1306 <update_db+0x166>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x34(%rbp),%esi
mov    %rax,%rdx
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ad <update_db+0x20d>
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
mov    %ecx,-0x1c(%rbp)
cmp    %ecx,%eax
je     135a <update_db+0x1ba>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x3c(%rbp),%esi
mov    %rax,%rdx
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ad <update_db+0x20d>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   10a0 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     138b <update_db+0x1eb>
mov    -0x18(%rbp),%rdi
call   10b0 <sqlite3_finalize@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     13a0 <update_db+0x200>
mov    -0x10(%rbp),%rdi
call   1090 <sqlite3_close@plt>
mov    $0x0,%al
call   1050 <sqlite3_shutdown@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_db>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e29(%rip),%rbx
mov    (%rbx),%ebp
lea    0xe38(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1030 <sqlite3_open@plt>
cmp    %eax,%ebp
jne    128c <update_db+0xec>
mov    (%rbx),%ebp
mov    0x8(%rsp),%rdi
lea    0xe3b(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
cmp    %eax,%ebp
jne    12a8 <update_db+0x108>
mov    (%rbx),%ebp
mov    0x8(%rsp),%rdi
lea    0xe45(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
cmp    %eax,%ebp
jne    12d8 <update_db+0x138>
mov    0x2d9f(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1070 <sqlite3_step@plt>
cmp    %eax,%ebx
jne    12ef <update_db+0x14f>
mov    0x10(%rsp),%rdi
xor    %esi,%esi
call   10a0 <sqlite3_column_text@plt>
lea    0xe43(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1271 <update_db+0xd1>
call   10b0 <sqlite3_finalize@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1280 <update_db+0xe0>
call   1090 <sqlite3_close@plt>
xor    %eax,%eax
call   1050 <sqlite3_shutdown@plt>
jmp    1313 <update_db+0x173>
mov    0x2d45(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd63(%rip),%rsi
jmp    12c2 <update_db+0x122>
mov    0x2d29(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd79(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1090 <sqlite3_close@plt>
jmp    130e <update_db+0x16e>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd76(%rip),%rdi
mov    %ebx,%esi
jmp    1304 <update_db+0x164>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd81(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@.str = [9 x i8] c":memory:\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Cannot open database: %s\0A\00"
@.str.2 = [24 x i8] c"SELECT SQLITE_VERSION()\00"
@.str.3 = [26 x i8] c"Failed to fetch data: %s\0A\00"
@.str.4 = [12 x i8] c"SELECT TEST\00"
@.str.5 = [34 x i8] c"Failed to prepare insert: %d, %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.6 = [24 x i8] c"Failed to step: %d, %s\0A\00"
@.str.7 = [22 x i8] c"Value from sqlite: %s\00"
define i32 @update_db() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* null, i32** %2
store i32* null, i32** %3
store i32 0, i32* %4
%5 = load i32, i32* @SQLITE_OK
%6 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %2)
store i32 %6, i32* %4
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %15
8: ; preds = %0
%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 ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %2
%14 = call i32 @sqlite3_close(i32* %13)
store i32 1, i32* %1
br label %65
15: ; preds = %0
%16 = load i32, i32* @SQLITE_OK
%17 = load i32*, i32** %2
%18 = call i32 @sqlite3_prepare_v2(i32* %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %3, i32* null)
store i32 %18, i32* %4
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32*, i32** %2
%23 = call i8* @sqlite3_errmsg(i32* %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %2
%26 = call i32 @sqlite3_close(i32* %25)
store i32 1, i32* %1
br label %65
27: ; preds = %15
%28 = load i32, i32* @SQLITE_OK
%29 = load i32*, i32** %2
%30 = call i32 @sqlite3_prepare_v2(i32* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 -1, i32** %3, i32* null)
store i32 %30, i32* %4
%31 = icmp ne i32 %28, %30
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* %4
%34 = load i32*, i32** %2
%35 = call i8* @sqlite3_errmsg(i32* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %33, i8* %35)
store i32 1, i32* %1
br label %65
37: ; preds = %27
%38 = load i32, i32* @SQLITE_ROW
%39 = load i32*, i32** %3
%40 = call i32 @sqlite3_step(i32* %39)
store i32 %40, i32* %4
%41 = icmp ne i32 %38, %40
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i32, i32* %4
%44 = load i32*, i32** %2
%45 = call i8* @sqlite3_errmsg(i32* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %43, i8* %45)
store i32 1, i32* %1
br label %65
47: ; preds = %37
%48 = load i32*, i32** %3
%49 = call i8* @sqlite3_column_text(i32* %48, i32 0)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %49)
%51 = load i32*, i32** %3
%52 = icmp ne i32* null, %51
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i32*, i32** %3
%55 = call i32 @sqlite3_finalize(i32* %54)
br label %56
56: ; preds = %53, %47
%57 = load i32*, i32** %2
%58 = icmp ne i32* null, %57
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32*, i32** %2
%61 = call i32 @sqlite3_close(i32* %60)
br label %62
62: ; preds = %59, %56
%63 = call i32 (...) @sqlite3_shutdown()
%64 = load i32, i32* %4
store i32 %64, i32* %1
br label %65
65: ; preds = %62, %42, %32, %20, %8
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@.str = [9 x i8] c":memory:\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Cannot open database: %s\0A\00"
@.str.2 = [24 x i8] c"SELECT SQLITE_VERSION()\00"
@.str.3 = [26 x i8] c"Failed to fetch data: %s\0A\00"
@.str.4 = [12 x i8] c"SELECT TEST\00"
@.str.5 = [34 x i8] c"Failed to prepare insert: %d, %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.6 = [24 x i8] c"Failed to step: %d, %s\0A\00"
@.str.7 = [22 x i8] c"Value from sqlite: %s\00"
define i32 @update_db() {
%1 = alloca i32*
%2 = alloca i32*
%3 = bitcast i32** %1 to i8*
store i32* null, i32** %1
%4 = bitcast i32** %2 to i8*
store i32* null, i32** %2
%5 = load i32, i32* @SQLITE_OK
%6 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %1)
%7 = icmp eq i32 %5, %6
br i1 %7, label %15, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32*, i32** %1
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %1
%14 = call i32 @sqlite3_close(i32* %13)
br label %60
15: ; preds = %0
%16 = load i32, i32* @SQLITE_OK
%17 = load i32*, i32** %1
%18 = call i32 @sqlite3_prepare_v2(i32* %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %2, i32* null)
%19 = icmp eq i32 %16, %18
br i1 %19, label %27, label %20
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32*, i32** %1
%23 = call i8* @sqlite3_errmsg(i32* %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %1
%26 = call i32 @sqlite3_close(i32* %25)
br label %60
27: ; preds = %15
%28 = load i32, i32* @SQLITE_OK
%29 = load i32*, i32** %1
%30 = call i32 @sqlite3_prepare_v2(i32* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 -1, i32** %2, i32* null)
%31 = icmp eq i32 %28, %30
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = load i32*, i32** %1
%34 = call i8* @sqlite3_errmsg(i32* %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %30, i8* %34)
br label %60
36: ; preds = %27
%37 = load i32, i32* @SQLITE_ROW
%38 = load i32*, i32** %2
%39 = call i32 @sqlite3_step(i32* %38)
%40 = icmp eq i32 %37, %39
br i1 %40, label %45, label %41
41: ; preds = %36
%42 = load i32*, i32** %1
%43 = call i8* @sqlite3_errmsg(i32* %42)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %39, i8* %43)
br label %60
45: ; preds = %36
%46 = load i32*, i32** %2
%47 = call i8* @sqlite3_column_text(i32* %46, i32 0)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %2
%50 = icmp eq i32* %49, null
br i1 %50, label %53, label %51
51: ; preds = %45
%52 = call i32 @sqlite3_finalize(i32* %49)
br label %53
53: ; preds = %51, %45
%54 = load i32*, i32** %1
%55 = icmp eq i32* %54, null
br i1 %55, label %58, label %56
56: ; preds = %53
%57 = call i32 @sqlite3_close(i32* %54)
br label %58
58: ; preds = %56, %53
%59 = call i32 (...) @sqlite3_shutdown()
br label %60
60: ; preds = %58, %41, %32, %20, %8
%61 = phi i32 [ 1, %8 ], [ 1, %20 ], [ 1, %32 ], [ 1, %41 ], [ %37, %58 ]
ret i32 %61
}