#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 */
#define SQLITE_DONE 129
#define SQLITE_ROW 128
int /*<<< orphan*/ SQLITE_STATIC;
char *beholddb_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                      int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, int,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int beholddb_get_param(sqlite3 *db, const char *param, const char **pvalue) {
  int rc;
  sqlite3_stmt *stmt;
  const char *sql = "select value from config where param = ?";
  (rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL)) ||
      (rc = sqlite3_bind_text(stmt, 1, param, -1, SQLITE_STATIC)) ||
      (rc = sqlite3_step(stmt));
  *pvalue = NULL;
  switch (rc) {
  case SQLITE_ROW:
    *pvalue = beholddb_column_text(stmt, 0);
  case SQLITE_DONE:
    rc = 0;
    break;
  default:
    rc = -1;
  }
  sqlite3_finalize(stmt);
  return rc;
}


x86 assembly (clang, -O0):
<beholddb_get_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <sqlite3_prepare_v2@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
jne    11e6 <beholddb_get_param+0x96>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    0x2e34(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1050 <sqlite3_bind_text@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
jne    11e6 <beholddb_get_param+0x96>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x80,%eax
je     121d <beholddb_get_param+0xcd>
jmp    120a <beholddb_get_param+0xba>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
je     1232 <beholddb_get_param+0xe2>
jmp    123e <beholddb_get_param+0xee>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1030 <beholddb_column_text@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x1c(%rbp)
jmp    1245 <beholddb_get_param+0xf5>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <sqlite3_finalize@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beholddb_get_param>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe9a(%rip),%rsi
xor    %ebx,%ebx
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1070 <sqlite3_prepare_v2@plt>
test   %eax,%eax
jne    11ad <beholddb_get_param+0x5d>
mov    0x8(%rsp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1050 <sqlite3_bind_text@plt>
test   %eax,%eax
jne    11ad <beholddb_get_param+0x5d>
mov    0x8(%rsp),%rdi
call   1040 <sqlite3_step@plt>
movq   $0x0,(%r14)
cmp    $0x81,%eax
je     11da <beholddb_get_param+0x8a>
cmp    $0x80,%eax
jne    11d5 <beholddb_get_param+0x85>
mov    0x8(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <beholddb_column_text@plt>
mov    %rax,(%r14)
jmp    11da <beholddb_get_param+0x8a>
mov    $0xffffffff,%ebx
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_finalize@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"select value from config where param = ?\00"
@SQLITE_STATIC = global i32 0
define i32 @beholddb_get_param(i32* %0, i8* %1, i8** %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i32*, i32** %4
%11 = load i8*, i8** %9
%12 = call i32 @sqlite3_prepare_v2(i32* %10, i8* %11, i32 -1, i32** %8, i32* null)
store i32 %12, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %3
%15 = load i32*, i32** %8
%16 = load i8*, i8** %5
%17 = load i32, i32* @SQLITE_STATIC
%18 = call i32 @sqlite3_bind_text(i32* %15, i32 1, i8* %16, i32 -1, i32 %17)
store i32 %18, i32* %7
%19 = icmp ne i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %14
%21 = load i32*, i32** %8
%22 = call i32 @sqlite3_step(i32* %21)
store i32 %22, i32* %7
%23 = icmp ne i32 %22, 0
br label %24
24: ; preds = %20, %14, %3
%25 = phi i1 [ true, %14 ], [ true, %3 ], [ %23, %20 ]
%26 = zext i1 %25 to i32
%27 = load i8**, i8*** %6
store i8* null, i8** %27
%28 = load i32, i32* %7
switch i32 %28, label %34 [
i32 128, label %29
i32 129, label %33
]
29: ; preds = %24
%30 = load i32*, i32** %8
%31 = call i8* @beholddb_column_text(i32* %30, i32 0)
%32 = load i8**, i8*** %6
store i8* %31, i8** %32
br label %33
33: ; preds = %24, %29
store i32 0, i32* %7
br label %35
34: ; preds = %24
store i32 -1, i32* %7
br label %35
35: ; preds = %34, %33
%36 = load i32*, i32** %8
%37 = call i32 @sqlite3_finalize(i32* %36)
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
@.str = [41 x i8] c"select value from config where param = ?\00"
@SQLITE_STATIC = global i32 0
define i32 @beholddb_get_param(i32* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = alloca i32*
%5 = bitcast i32** %4 to i8*
%6 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = load i32*, i32** %4
%10 = load i32, i32* @SQLITE_STATIC
%11 = call i32 @sqlite3_bind_text(i32* %9, i32 1, i8* %1, i32 -1, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32*, i32** %4
%15 = call i32 @sqlite3_step(i32* %14)
br label %16
16: ; preds = %13, %8, %3
%17 = phi i32 [ %6, %3 ], [ %11, %8 ], [ %15, %13 ]
store i8* null, i8** %2
switch i32 %17, label %21 [
i32 128, label %18
i32 129, label %22
]
18: ; preds = %16
%19 = load i32*, i32** %4
%20 = call i8* @beholddb_column_text(i32* %19, i32 0)
store i8* %20, i8** %2
br label %22
21: ; preds = %16
br label %22
22: ; preds = %18, %16, %21
%23 = phi i32 [ -1, %21 ], [ 0, %16 ], [ 0, %18 ]
%24 = load i32*, i32** %4
%25 = call i32 @sqlite3_finalize(i32* %24)
ret i32 %23
}