#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 */
scalar_t__ SQLITE_DONE;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ printf(char *, char *);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *,
                                      int /*<<< orphan*/, int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int getSQLResultInt(sqlite3 *db, char *sql) {
  int result;
  sqlite3_stmt *stmt;
  sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
  if (sqlite3_step(stmt) != SQLITE_ROW) {
    printf("ERROR 1 reading data: %s\n", sqlite3_errmsg(db));
  }
  result = sqlite3_column_int(stmt, 0);
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    printf("ERROR 2 reading data: %s\n", sqlite3_errmsg(db));
  }
  sqlite3_finalize(stmt);
  return result;
}


x86 assembly (clang, -O0):
<getSQLResultInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
je     11e2 <getSQLResultInt+0x72>
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    %rax,%rsi
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%rax
je     1221 <getSQLResultInt+0xb1>
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    %rax,%rsi
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSQLResultInt>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    (%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11c0 <getSQLResultInt+0x50>
mov    %rbx,%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xe48(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rsp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
je     11f9 <getSQLResultInt+0x89>
mov    %rbx,%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xe29(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rsp),%rdi
call   1080 <sqlite3_finalize@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_ROW = global i64 0
@.str = [26 x i8] c"ERROR 1 reading data: %s\0A\00"
@SQLITE_DONE = global i64 0
@.str.1 = [26 x i8] c"ERROR 2 reading data: %s\0A\00"
define i32 @getSQLResultInt(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i32*, i32** %3
%8 = load i8*, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @sqlite3_prepare_v2(i32* %7, i8* %8, i32 %10, i32** %6, i32* null)
%12 = load i32*, i32** %6
%13 = call i64 @sqlite3_step(i32* %12)
%14 = load i64, i64* @SQLITE_ROW
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32*, i32** %3
%18 = call i8* @sqlite3_errmsg(i32* %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %2
%21 = load i32*, i32** %6
%22 = call i32 @sqlite3_column_int(i32* %21, i32 0)
store i32 %22, i32* %5
%23 = load i32*, i32** %6
%24 = call i64 @sqlite3_step(i32* %23)
%25 = load i64, i64* @SQLITE_DONE
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i32*, i32** %3
%29 = call i8* @sqlite3_errmsg(i32* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %20
%32 = load i32*, i32** %6
%33 = call i32 @sqlite3_finalize(i32* %32)
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@SQLITE_ROW = global i64 0
@.str = [26 x i8] c"ERROR 1 reading data: %s\0A\00"
@SQLITE_DONE = global i64 0
@.str.1 = [26 x i8] c"ERROR 2 reading data: %s\0A\00"
define i32 @getSQLResultInt(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = tail call i32 @strlen(i8* %1)
%6 = call i32 @sqlite3_prepare_v2(i32* %0, i8* %1, i32 %5, i32** %3, i32* null)
%7 = load i32*, i32** %3
%8 = call i64 @sqlite3_step(i32* %7)
%9 = load i64, i64* @SQLITE_ROW
%10 = icmp eq i64 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i8* @sqlite3_errmsg(i32* %0)
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %2
%15 = load i32*, i32** %3
%16 = call i32 @sqlite3_column_int(i32* %15, i32 0)
%17 = load i32*, i32** %3
%18 = call i64 @sqlite3_step(i32* %17)
%19 = load i64, i64* @SQLITE_DONE
%20 = icmp eq i64 %18, %19
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = call i8* @sqlite3_errmsg(i32* %0)
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %14
%25 = load i32*, i32** %3
%26 = call i32 @sqlite3_finalize(i32* %25)
ret i32 %16
}