#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*/ SQLITE_STATIC;
int sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *,
                      int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare(int /*<<< orphan*/ *, char const *, int,
                    int /*<<< orphan*/ **, int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int user_exists(sqlite3 *sqlite, const char *user) {
  sqlite3_stmt *sqlite_stmt;
  const char *query = "SELECT 1 FROM user WHERE name = ?;";
  int rval;
  rval = sqlite3_prepare(sqlite, query, -1, &sqlite_stmt, 0);
  if (rval != SQLITE_OK)
    return 0;
  rval = sqlite3_bind_text(sqlite_stmt, 1, user, strlen(user), SQLITE_STATIC);
  if (rval != SQLITE_OK)
    return 0;
  rval = sqlite3_step(sqlite_stmt);
  sqlite3_finalize(sqlite_stmt);
  return (rval == SQLITE_ROW) ? 1 : 0;
}


x86 assembly (clang, -O0):
<user_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%eax
je     11a5 <user_exists+0x55>
movl   $0x0,-0x4(%rbp)
jmp    122d <user_exists+0xdd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
mov    0x2e09(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
call   1050 <sqlite3_bind_text@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%eax
je     11fd <user_exists+0xad>
movl   $0x0,-0x4(%rbp)
jmp    122d <user_exists+0xdd>
mov    -0x20(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    -0x2c(%rbp),%edx
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_exists>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe9f(%rip),%rsi
mov    %rsp,%rcx
xor    %ebx,%ebx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare@plt>
mov    0x2e6e(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    11ce <user_exists+0x7e>
mov    (%rsp),%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    0x2e46(%rip),%rcx
mov    (%rcx),%r8d
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1050 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%eax
jne    11ce <user_exists+0x7e>
mov    (%rsp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    0x2e09(%rip),%rax
xor    %ebx,%ebx
cmp    (%rax),%ebp
sete   %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"SELECT 1 FROM user WHERE name = ?;\00"
@SQLITE_OK = global i32 0
@SQLITE_STATIC = global i32 0
@SQLITE_ROW = global i32 0
define i32 @user_exists(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i32*, i32** %4
%10 = load i8*, i8** %7
%11 = call i32 @sqlite3_prepare(i32* %9, i8* %10, i32 -1, i32** %6, i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = load i32, i32* @SQLITE_OK
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %37
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = load i32, i32* @SQLITE_STATIC
%22 = call i32 @sqlite3_bind_text(i32* %17, i32 1, i8* %18, i32 %20, i32 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* @SQLITE_OK
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %16
store i32 0, i32* %3
br label %37
27: ; preds = %16
%28 = load i32*, i32** %6
%29 = call i32 @sqlite3_step(i32* %28)
store i32 %29, i32* %8
%30 = load i32*, i32** %6
%31 = call i32 @sqlite3_finalize(i32* %30)
%32 = load i32, i32* %8
%33 = load i32, i32* @SQLITE_ROW
%34 = icmp eq i32 %32, %33
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 1, i32 0
store i32 %36, i32* %3
br label %37
37: ; preds = %27, %26, %15
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [35 x i8] c"SELECT 1 FROM user WHERE name = ?;\00"
@SQLITE_OK = global i32 0
@SQLITE_STATIC = global i32 0
@SQLITE_ROW = global i32 0
define i32 @user_exists(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i32 @sqlite3_prepare(i32* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %3, i32 0)
%6 = load i32, i32* @SQLITE_OK
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %23
8: ; preds = %2
%9 = load i32*, i32** %3
%10 = call i32 @strlen(i8* %1)
%11 = load i32, i32* @SQLITE_STATIC
%12 = call i32 @sqlite3_bind_text(i32* %9, i32 1, i8* %1, i32 %10, i32 %11)
%13 = load i32, i32* @SQLITE_OK
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %8
%16 = load i32*, i32** %3
%17 = call i32 @sqlite3_step(i32* %16)
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_finalize(i32* %18)
%20 = load i32, i32* @SQLITE_ROW
%21 = icmp eq i32 %17, %20
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %8, %2, %15
%24 = phi i32 [ %22, %15 ], [ 0, %2 ], [ 0, %8 ]
ret i32 %24
}