#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *,
                                     int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int sql_label_exists(sqlite3 *db, char *label) {
  int entries;
  int err;
  sqlite3_stmt *res;
  err = sqlite3_prepare_v2(
      db, "SELECT count(*) from passwords WHERE label = ?;", -1, &res, 0);
  if (err != SQLITE_OK) {
    fprintf(stderr, "SQL prepare failure: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(1);
  } else {
    sqlite3_bind_text(res, 1, label, strlen(label), NULL);
  }
  err = sqlite3_step(res);
  if (err == SQLITE_ROW) {
    entries = sqlite3_column_int(res, 0);
  }
  sqlite3_finalize(res);
  return entries;
}


x86 assembly (clang, -O0):
<sql_label_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%eax
je     121b <sql_label_exists+0x7b>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe2d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d6d(%rip),%rcx
cmp    (%rcx),%eax
jne    1279 <sql_label_exists+0xd9>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sql_label_exists>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe4a(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
jne    122e <sql_label_exists+0x8e>
mov    0x8(%rsp),%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%eax
jne    1218 <sql_label_exists+0x78>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2da3(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xdea(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1080 <sqlite3_close@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"SELECT count(*) from passwords WHERE label = ?;\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"SQL prepare failure: %s\0A\00"
@SQLITE_ROW = global i32 0
define i32 @sql_label_exists(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%8 = load i32*, i32** %3
%9 = call i32 @sqlite3_prepare_v2(i32* %8, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %7, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @SQLITE_OK
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32*, i32** %3
%16 = call i8* @sqlite3_errmsg(i32* %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_close(i32* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32*, i32** %7
%23 = load i8*, i8** %4
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @sqlite3_bind_text(i32* %22, i32 1, i8* %23, i32 %25, i32* null)
br label %27
27: ; preds = %21
%28 = load i32*, i32** %7
%29 = call i32 @sqlite3_step(i32* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* @SQLITE_ROW
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32*, i32** %7
%35 = call i32 @sqlite3_column_int(i32* %34, i32 0)
store i32 %35, i32* %5
br label %36
36: ; preds = %33, %27
%37 = load i32*, i32** %7
%38 = call i32 @sqlite3_finalize(i32* %37)
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@.str = [48 x i8] c"SELECT count(*) from passwords WHERE label = ?;\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"SQL prepare failure: %s\0A\00"
@SQLITE_ROW = global i32 0
define i32 @sql_label_exists(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([48 x i8], [48 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 %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i8* @sqlite3_errmsg(i32* %0)
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @sqlite3_close(i32* %0)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = call i32 @strlen(i8* %1)
%17 = call i32 @sqlite3_bind_text(i32* %15, i32 1, i8* %1, i32 %16, i32* null)
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_step(i32* %18)
%20 = load i32, i32* @SQLITE_ROW
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32*, i32** %3
%24 = call i32 @sqlite3_column_int(i32* %23, i32 0)
br label %25
25: ; preds = %22, %14
%26 = phi i32 [ %24, %22 ], [ undef, %14 ]
%27 = load i32*, i32** %3
%28 = call i32 @sqlite3_finalize(i32* %27)
ret i32 %26
}