#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_OK;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ logprintf(int /*<<< orphan*/, char *);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
int sqlite_exec_select(int /*<<< orphan*/ *);
int sqlite_get_permissions_by_permission(sqlite3 *db, const char *permission) {
  char *sql = "SELECT api_user, api_permission FROM api_access WHERE "
              "api_permission LIKE ?";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, permission, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Cannot bind permission.\n");
    return 3;
  }
  return sqlite_exec_select(stmt);
}


x86 assembly (clang, -O0):
<sqlite_get_permissions_by_permission>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <database_prepare@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <sqlite_get_permissions_by_permission+0x43>
movl   $0x2,-0x4(%rbp)
jmp    11da <sqlite_get_permissions_by_permission+0x9a>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e46(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1040 <sqlite3_bind_text@plt>
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <sqlite_get_permissions_by_permission+0x8e>
xor    %edi,%edi
lea    0xe8f(%rip),%rsi
call   1060 <logprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    11da <sqlite_get_permissions_by_permission+0x9a>
mov    -0x28(%rbp),%rdi
call   1050 <sqlite_exec_select@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_permissions_by_permission>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xeb2(%rip),%rsi
call   1030 <database_prepare@plt>
test   %rax,%rax
je     1195 <sqlite_get_permissions_by_permission+0x55>
mov    %rax,%rbx
mov    0x2e76(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
call   1040 <sqlite3_bind_text@plt>
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    119c <sqlite_get_permissions_by_permission+0x5c>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sqlite_exec_select@plt>
mov    $0x2,%eax
jmp    11af <sqlite_get_permissions_by_permission+0x6f>
lea    0xea9(%rip),%rsi
xor    %edi,%edi
call   1060 <logprintf@plt>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [76 x i8] c"SELECT api_user, api_permission FROM api_access WHERE api_permission LIKE ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [25 x i8] c"Cannot bind permission.\0A\00"
define i32 @sqlite_get_permissions_by_permission(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i32*, i32** %4
%9 = load i8*, i8** %6
%10 = call i32* @database_prepare(i32* %8, i8* %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 2, i32* %3
br label %26
14: ; preds = %2
%15 = load i32*, i32** %7
%16 = load i8*, i8** %5
%17 = load i32, i32* @SQLITE_STATIC
%18 = call i64 @sqlite3_bind_text(i32* %15, i32 1, i8* %16, i32 -1, i32 %17)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @logprintf(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %3
br label %26
23: ; preds = %14
%24 = load i32*, i32** %7
%25 = call i32 @sqlite_exec_select(i32* %24)
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %21, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [76 x i8] c"SELECT api_user, api_permission FROM api_access WHERE api_permission LIKE ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [25 x i8] c"Cannot bind permission.\0A\00"
define i32 @sqlite_get_permissions_by_permission(i32* %0, i8* %1) {
%3 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = load i32, i32* @SQLITE_STATIC
%7 = tail call i64 @sqlite3_bind_text(i32* %3, i32 1, i8* %1, i32 -1, i32 %6)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @logprintf(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %5
%13 = tail call i32 @sqlite_exec_select(i32* %3)
br label %14
14: ; preds = %2, %12, %10
%15 = phi i32 [ 3, %10 ], [ %13, %12 ], [ 2, %2 ]
ret i32 %15
}