#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;

/* Variables and functions */
int SQLITE_DONE;
int SQLITE_ROW;
int /*<<< orphan*/ printf(char *, char const *, char const *, ...);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int sqlite_exec_select(sqlite3_stmt *stmt) {
  int status;
  const char *user;
  const char *permission;
  printf("%20s | %10s\n%s\n", "User", "Permission",
         "---------------------+-----------");
  while ((status = sqlite3_step(stmt)) == SQLITE_ROW) {
    user = (const char *)sqlite3_column_text(stmt, 0);
    permission = (const char *)sqlite3_column_text(stmt, 1);
    printf("%20s | %10s\n", user, permission);
  }
  sqlite3_finalize(stmt);
  if (status == SQLITE_DONE) {
    return 0;
  }
  return status;
}


x86 assembly (clang, -O0):
<sqlite_exec_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xeb6(%rip),%rsi
lea    0xeb4(%rip),%rdx
lea    0xeb8(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
jne    11c6 <sqlite_exec_select+0x86>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_text@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1050 <sqlite3_column_text@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116f <sqlite_exec_select+0x2f>
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_finalize@plt>
mov    -0x14(%rbp),%eax
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%eax
jne    11ed <sqlite_exec_select+0xad>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <sqlite_exec_select+0xb3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_exec_select>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xeae(%rip),%rdi
lea    0xeb7(%rip),%rsi
lea    0xeb5(%rip),%rdx
lea    0xeb9(%rip),%rcx
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,%ebp
mov    0x2e56(%rip),%r12
cmp    (%r12),%eax
jne    11ca <sqlite_exec_select+0x8a>
lea    0xeb3(%rip),%r15
nop
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_text@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <sqlite3_column_text@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
cmp    (%r12),%eax
je     1190 <sqlite_exec_select+0x50>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <sqlite3_finalize@plt>
mov    0x2e07(%rip),%rax
cmp    (%rax),%ebp
cmovne %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"%20s | %10s\0A%s\0A\00"
@.str.1 = [5 x i8] c"User\00"
@.str.2 = [11 x i8] c"Permission\00"
@.str.3 = [34 x i8] c"---------------------+-----------\00"
@SQLITE_ROW = global i32 0
@.str.4 = [13 x i8] c"%20s | %10s\0A\00"
@SQLITE_DONE = global i32 0
define i32 @sqlite_exec_select(i32* %0) {
%2 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i32 @sqlite3_step(i32* %0)
%4 = load i32, i32* @SQLITE_ROW
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %15
6: ; preds = %1, %6
%7 = tail call i64 @sqlite3_column_text(i32* %0, i32 0)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @sqlite3_column_text(i32* %0, i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %8, i8* %10)
%12 = tail call i32 @sqlite3_step(i32* %0)
%13 = load i32, i32* @SQLITE_ROW
%14 = icmp eq i32 %12, %13
br i1 %14, label %6, label %15
15: ; preds = %6, %1
%16 = phi i32 [ %3, %1 ], [ %12, %6 ]
%17 = tail call i32 @sqlite3_finalize(i32* %0)
%18 = load i32, i32* @SQLITE_DONE
%19 = icmp eq i32 %16, %18
%20 = select i1 %19, i32 0, i32 %16
ret i32 %20
}