#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;
int SQLITE_ROW;
int /*<<< orphan*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, char const *, int);
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_all_popd(sqlite3 *db) {
  char *sql = "SELECT pop_user, pop_lock FROM popd";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  int status;
  const char *user;
  int lock;
  while ((status = sqlite3_step(stmt)) == SQLITE_ROW) {
    user = (const char *)sqlite3_column_text(stmt, 0);
    lock = sqlite3_column_int(stmt, 1);
    printf("%s | %d\n", user, lock);
  }
  sqlite3_finalize(stmt);
  if (status == SQLITE_DONE) {
    return 0;
  }
  return status;
}


x86 assembly (clang, -O0):
<sqlite_get_all_popd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <database_prepare@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119f <sqlite_get_all_popd+0x3f>
movl   $0x2,-0x4(%rbp)
jmp    1224 <sqlite_get_all_popd+0xc4>
jmp    11a4 <sqlite_get_all_popd+0x44>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
jne    11f7 <sqlite_get_all_popd+0x97>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
jmp    11a4 <sqlite_get_all_popd+0x44>
mov    -0x20(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
mov    -0x24(%rbp),%eax
mov    0x2dd6(%rip),%rcx
cmp    (%rcx),%eax
jne    121e <sqlite_get_all_popd+0xbe>
movl   $0x0,-0x4(%rbp)
jmp    1224 <sqlite_get_all_popd+0xc4>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_all_popd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rsi
call   1060 <database_prepare@plt>
test   %rax,%rax
je     11ee <sqlite_get_all_popd+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,%ebp
mov    0x2e4c(%rip),%r15
cmp    (%r15),%eax
jne    11d6 <sqlite_get_all_popd+0x76>
lea    0xe8c(%rip),%r14
nopl   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    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
cmp    (%r15),%eax
je     11a0 <sqlite_get_all_popd+0x40>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <sqlite3_finalize@plt>
mov    0x2dfb(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%ebp
cmovne %ebp,%eax
jmp    11f3 <sqlite_get_all_popd+0x93>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"SELECT pop_user, pop_lock FROM popd\00"
@SQLITE_ROW = global i32 0
@.str.1 = [9 x i8] c"%s | %d\0A\00"
@SQLITE_DONE = global i32 0
define i32 @sqlite_get_all_popd(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %3
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8** %4
%9 = load i32*, i32** %3
%10 = load i8*, i8** %4
%11 = call i32* @database_prepare(i32* %9, i8* %10)
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 2, i32* %2
br label %39
15: ; preds = %1
br label %16
16: ; preds = %21, %15
%17 = load i32*, i32** %5
%18 = call i32 @sqlite3_step(i32* %17)
store i32 %18, i32* %6
%19 = load i32, i32* @SQLITE_ROW
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i32*, i32** %5
%23 = call i64 @sqlite3_column_text(i32* %22, i32 0)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %7
%25 = load i32*, i32** %5
%26 = call i32 @sqlite3_column_int(i32* %25, i32 1)
store i32 %26, i32* %8
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %28)
br label %16
30: ; preds = %16
%31 = load i32*, i32** %5
%32 = call i32 @sqlite3_finalize(i32* %31)
%33 = load i32, i32* %6
%34 = load i32, i32* @SQLITE_DONE
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 0, i32* %2
br label %39
37: ; preds = %30
%38 = load i32, i32* %6
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %36, %14
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [36 x i8] c"SELECT pop_user, pop_lock FROM popd\00"
@SQLITE_ROW = global i32 0
@.str.1 = [9 x i8] c"%s | %d\0A\00"
@SQLITE_DONE = global i32 0
define i32 @sqlite_get_all_popd(i32* %0) {
%2 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = tail call i32 @sqlite3_step(i32* %2)
%6 = load i32, i32* @SQLITE_ROW
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %16
8: ; preds = %4, %8
%9 = tail call i64 @sqlite3_column_text(i32* %2, i32 0)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @sqlite3_column_int(i32* %2, i32 1)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %11)
%13 = tail call i32 @sqlite3_step(i32* %2)
%14 = load i32, i32* @SQLITE_ROW
%15 = icmp eq i32 %13, %14
br i1 %15, label %8, label %16
16: ; preds = %8, %4
%17 = phi i32 [ %5, %4 ], [ %13, %8 ]
%18 = tail call i32 @sqlite3_finalize(i32* %2)
%19 = load i32, i32* @SQLITE_DONE
%20 = icmp eq i32 %17, %19
%21 = select i1 %20, i32 0, i32 %17
br label %22
22: ; preds = %1, %16
%23 = phi i32 [ %21, %16 ], [ 2, %1 ]
ret i32 %23
}