#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_DONE;
scalar_t__ SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ logprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
int sqlite3_column_int(int /*<<< orphan*/ *, int);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int sqlite_get_popd(sqlite3 *db, const char *username) {
  char *sql = "SELECT pop_user, pop_lock FROM popd WHERE pop_user LIKE ?";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, username, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Cannot bind expression.\n");
    return 3;
  }
  int status;
  const char *user;
  int lock;
  printf("%20s | %5s\n%s\n", "User", "Lock", "---------------------+------");
  while ((status = sqlite3_step(stmt)) == SQLITE_ROW) {
    user = (const char *)sqlite3_column_text(stmt, 0);
    lock = sqlite3_column_int(stmt, 1);
    printf("%20s | %5d\n", user, lock);
  }
  sqlite3_finalize(stmt);
  if (status == SQLITE_DONE) {
    return 0;
  }
  return status;
}


x86 assembly (clang, -O0):
<sqlite_get_popd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe69(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <database_prepare@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c3 <sqlite_get_popd+0x43>
movl   $0x2,-0x4(%rbp)
jmp    12b3 <sqlite_get_popd+0x133>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e06(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%rax
je     120e <sqlite_get_popd+0x8e>
xor    %edi,%edi
lea    0xe3d(%rip),%rsi
call   10a0 <logprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    12b3 <sqlite_get_popd+0x133>
lea    0xe3e(%rip),%rdi
lea    0xe46(%rip),%rsi
lea    0xe44(%rip),%rdx
lea    0xe42(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%eax
jne    1286 <sqlite_get_popd+0x106>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1231 <sqlite_get_popd+0xb1>
mov    -0x28(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    -0x2c(%rbp),%eax
mov    0x2d37(%rip),%rcx
cmp    (%rcx),%eax
jne    12ad <sqlite_get_popd+0x12d>
movl   $0x0,-0x4(%rbp)
jmp    12b3 <sqlite_get_popd+0x133>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_popd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
lea    0xe6e(%rip),%rsi
call   1060 <database_prepare@plt>
test   %rax,%rax
je     1270 <sqlite_get_popd+0xf0>
mov    %rax,%rbx
mov    0x2e2e(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jne    1278 <sqlite_get_popd+0xf8>
lea    0xe7a(%rip),%rdi
lea    0xe82(%rip),%rsi
lea    0xe80(%rip),%rdx
lea    0xe7e(%rip),%rcx
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,%ebp
mov    0x2dbf(%rip),%r12
cmp    (%r12),%eax
jne    1259 <sqlite_get_popd+0xd9>
lea    0xe73(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <sqlite3_column_int@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
cmp    (%r12),%eax
je     1220 <sqlite_get_popd+0xa0>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <sqlite3_finalize@plt>
mov    0x2d68(%rip),%rax
cmp    (%rax),%ebp
cmovne %ebp,%r14d
jmp    128c <sqlite_get_popd+0x10c>
mov    $0x2,%r14d
jmp    128c <sqlite_get_popd+0x10c>
lea    0xdbb(%rip),%rsi
xor    %edi,%edi
call   10a0 <logprintf@plt>
mov    $0x3,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"SELECT pop_user, pop_lock FROM popd WHERE pop_user LIKE ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [25 x i8] c"Cannot bind expression.\0A\00"
@.str.2 = [15 x i8] c"%20s | %5s\0A%s\0A\00"
@.str.3 = [5 x i8] c"User\00"
@.str.4 = [5 x i8] c"Lock\00"
@.str.5 = [29 x i8] c"---------------------+------\00"
@SQLITE_ROW = global i32 0
@.str.6 = [12 x i8] c"%20s | %5d\0A\00"
@SQLITE_DONE = global i32 0
define i32 @sqlite_get_popd(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i32*, i32** %4
%12 = load i8*, i8** %6
%13 = call i32* @database_prepare(i32* %11, i8* %12)
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i32 2, i32* %3
br label %51
17: ; preds = %2
%18 = load i32*, i32** %7
%19 = load i8*, i8** %5
%20 = load i32, i32* @SQLITE_STATIC
%21 = call i64 @sqlite3_bind_text(i32* %18, i32 1, i8* %19, i32 -1, i32 %20)
%22 = load i64, i64* @SQLITE_OK
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = 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 %51
26: ; preds = %17
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %33, %26
%29 = load i32*, i32** %7
%30 = call i32 @sqlite3_step(i32* %29)
store i32 %30, i32* %8
%31 = load i32, i32* @SQLITE_ROW
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = load i32*, i32** %7
%35 = call i64 @sqlite3_column_text(i32* %34, i32 0)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %9
%37 = load i32*, i32** %7
%38 = call i32 @sqlite3_column_int(i32* %37, i32 1)
store i32 %38, i32* %10
%39 = load i8*, i8** %9
%40 = load i32, i32* %10
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %39, i32 %40)
br label %28
42: ; preds = %28
%43 = load i32*, i32** %7
%44 = call i32 @sqlite3_finalize(i32* %43)
%45 = load i32, i32* %8
%46 = load i32, i32* @SQLITE_DONE
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 0, i32* %3
br label %51
49: ; preds = %42
%50 = load i32, i32* %8
store i32 %50, i32* %3
br label %51
51: ; preds = %49, %48, %24, %16
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [58 x i8] c"SELECT pop_user, pop_lock FROM popd WHERE pop_user LIKE ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [25 x i8] c"Cannot bind expression.\0A\00"
@.str.2 = [15 x i8] c"%20s | %5s\0A%s\0A\00"
@.str.3 = [5 x i8] c"User\00"
@.str.4 = [5 x i8] c"Lock\00"
@.str.5 = [29 x i8] c"---------------------+------\00"
@SQLITE_ROW = global i32 0
@.str.6 = [12 x i8] c"%20s | %5d\0A\00"
@SQLITE_DONE = global i32 0
define i32 @sqlite_get_popd(i32* %0, i8* %1) {
%3 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %31, 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 %31
12: ; preds = %5
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @sqlite3_step(i32* %3)
%15 = load i32, i32* @SQLITE_ROW
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %12, %17
%18 = tail call i64 @sqlite3_column_text(i32* %3, i32 0)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i32 @sqlite3_column_int(i32* %3, i32 1)
%21 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %19, i32 %20)
%22 = tail call i32 @sqlite3_step(i32* %3)
%23 = load i32, i32* @SQLITE_ROW
%24 = icmp eq i32 %22, %23
br i1 %24, label %17, label %25
25: ; preds = %17, %12
%26 = phi i32 [ %14, %12 ], [ %22, %17 ]
%27 = tail call i32 @sqlite3_finalize(i32* %3)
%28 = load i32, i32* @SQLITE_DONE
%29 = icmp eq i32 %26, %28
%30 = select i1 %29, i32 0, i32 %26
br label %31
31: ; preds = %2, %25, %10
%32 = phi i32 [ 3, %10 ], [ %30, %25 ], [ 2, %2 ]
ret i32 %32
}