#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 *, char *, char *, ...);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int sqlite_get_msa(sqlite3 *db, const char *username) {
  char *sql = "SELECT smtpd_user, smtpd_router, smtpd_route FROM smtpd WHERE "
              "smtpd_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;
  printf("%20s | %10s | %15s\n%s\n", "User", "Router", "Argument",
         "---------------------+------------+-----------------");
  while ((status = sqlite3_step(stmt)) == SQLITE_ROW) {
    printf("%20s | %10s | %15s\n", (char *)sqlite3_column_text(stmt, 0),
           (char *)sqlite3_column_text(stmt, 1),
           sqlite3_column_text(stmt, 2) ? (char *)sqlite3_column_text(stmt, 2)
                                        : "");
  }
  sqlite3_finalize(stmt);
  return (status == SQLITE_DONE) ? 0 : status;
}


x86 assembly (clang, -O0):
<sqlite_get_msa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <database_prepare@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b3 <sqlite_get_msa+0x43>
movl   $0x2,-0x4(%rbp)
jmp    12f3 <sqlite_get_msa+0x183>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e16(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%rax
je     11fe <sqlite_get_msa+0x8e>
xor    %edi,%edi
lea    0xe63(%rip),%rsi
call   1090 <logprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    12f3 <sqlite_get_msa+0x183>
lea    0xe64(%rip),%rdi
lea    0xe74(%rip),%rsi
lea    0xe72(%rip),%rdx
lea    0xe72(%rip),%rcx
lea    0xe74(%rip),%r8
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%eax
jne    12c2 <sqlite_get_msa+0x152>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1060 <sqlite3_column_text@plt>
cmp    $0x0,%rax
je     1293 <sqlite_get_msa+0x123>
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,-0x48(%rbp)
jmp    12a3 <sqlite_get_msa+0x133>
lea    0xdce(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12a3 <sqlite_get_msa+0x133>
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rcx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1228 <sqlite_get_msa+0xb8>
mov    -0x28(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
mov    -0x2c(%rbp),%eax
mov    0x2cfb(%rip),%rcx
cmp    (%rcx),%eax
jne    12e7 <sqlite_get_msa+0x177>
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
jmp    12ed <sqlite_get_msa+0x17d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_get_msa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xe7b(%rip),%rsi
call   1050 <database_prepare@plt>
test   %rax,%rax
je     1282 <sqlite_get_msa+0x112>
mov    %rax,%rbx
mov    0x2e3b(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
jne    128a <sqlite_get_msa+0x11a>
lea    0xe9d(%rip),%rdi
lea    0xead(%rip),%rsi
lea    0xeab(%rip),%rdx
lea    0xeab(%rip),%rcx
lea    0xead(%rip),%r8
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,%ebp
mov    0x2dc5(%rip),%r13
cmp    0x0(%r13),%eax
jne    12a5 <sqlite_get_msa+0x135>
lea    0xe54(%rip),%r14
lea    0xeaf(%rip),%r15
jmp    123e <sqlite_get_msa+0xce>
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
cmp    0x0(%r13),%eax
jne    12a0 <sqlite_get_msa+0x130>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <sqlite3_column_text@plt>
mov    %r14,%rcx
test   %rax,%rax
je     1220 <sqlite_get_msa+0xb0>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,%rcx
jmp    1220 <sqlite_get_msa+0xb0>
mov    $0x2,%r14d
jmp    12ba <sqlite_get_msa+0x14a>
lea    0xdbf(%rip),%rsi
xor    %edi,%edi
call   1090 <logprintf@plt>
mov    $0x3,%r14d
jmp    12ba <sqlite_get_msa+0x14a>
mov    %eax,%ebp
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1080 <sqlite3_finalize@plt>
mov    0x2d1c(%rip),%rax
cmp    (%rax),%ebp
cmovne %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [80 x i8] c"SELECT smtpd_user, smtpd_router, smtpd_route FROM smtpd WHERE smtpd_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 = [23 x i8] c"%20s | %10s | %15s\0A%s\0A\00"
@.str.3 = [5 x i8] c"User\00"
@.str.4 = [7 x i8] c"Router\00"
@.str.5 = [9 x i8] c"Argument\00"
@.str.6 = [53 x i8] c"---------------------+------------+-----------------\00"
@SQLITE_ROW = global i32 0
@.str.7 = [20 x i8] c"%20s | %10s | %15s\0A\00"
@.str.8 = [1 x i8] zeroinitializer
@SQLITE_DONE = global i32 0
define i32 @sqlite_get_msa(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i32*, i32** %4
%10 = load i8*, i8** %6
%11 = call i32* @database_prepare(i32* %9, i8* %10)
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 2, i32* %3
br label %60
15: ; preds = %2
%16 = load i32*, i32** %7
%17 = load i8*, i8** %5
%18 = load i32, i32* @SQLITE_STATIC
%19 = call i64 @sqlite3_bind_text(i32* %16, i32 1, i8* %17, i32 -1, i32 %18)
%20 = load i64, i64* @SQLITE_OK
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = 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 %60
24: ; preds = %15
%25 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 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 ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
br label %26
26: ; preds = %46, %24
%27 = load i32*, i32** %7
%28 = call i32 @sqlite3_step(i32* %27)
store i32 %28, i32* %8
%29 = load i32, i32* @SQLITE_ROW
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %49
31: ; preds = %26
%32 = load i32*, i32** %7
%33 = call i64 @sqlite3_column_text(i32* %32, i32 0)
%34 = inttoptr i64 %33 to i8*
%35 = load i32*, i32** %7
%36 = call i64 @sqlite3_column_text(i32* %35, i32 1)
%37 = inttoptr i64 %36 to i8*
%38 = load i32*, i32** %7
%39 = call i64 @sqlite3_column_text(i32* %38, i32 2)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %31
%42 = load i32*, i32** %7
%43 = call i64 @sqlite3_column_text(i32* %42, i32 2)
%44 = inttoptr i64 %43 to i8*
br label %46
45: ; preds = %31
br label %46
46: ; preds = %45, %41
%47 = phi i8* [ %44, %41 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0), %45 ]
%48 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %34, i8* %37, i8* %47)
br label %26
49: ; preds = %26
%50 = load i32*, i32** %7
%51 = call i32 @sqlite3_finalize(i32* %50)
%52 = load i32, i32* %8
%53 = load i32, i32* @SQLITE_DONE
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %49
br label %58
56: ; preds = %49
%57 = load i32, i32* %8
br label %58
58: ; preds = %56, %55
%59 = phi i32 [ 0, %55 ], [ %57, %56 ]
store i32 %59, i32* %3
br label %60
60: ; preds = %58, %22, %14
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [80 x i8] c"SELECT smtpd_user, smtpd_router, smtpd_route FROM smtpd WHERE smtpd_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 = [23 x i8] c"%20s | %10s | %15s\0A%s\0A\00"
@.str.3 = [5 x i8] c"User\00"
@.str.4 = [7 x i8] c"Router\00"
@.str.5 = [9 x i8] c"Argument\00"
@.str.6 = [53 x i8] c"---------------------+------------+-----------------\00"
@SQLITE_ROW = global i32 0
@.str.7 = [20 x i8] c"%20s | %10s | %15s\0A\00"
@.str.8 = [1 x i8] zeroinitializer
@SQLITE_DONE = global i32 0
define i32 @sqlite_get_msa(i32* %0, i8* %1) {
%3 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %39, 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 %39
12: ; preds = %5
%13 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 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 ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, 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 %33
17: ; preds = %12, %27
%18 = tail call i64 @sqlite3_column_text(i32* %3, i32 0)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i64 @sqlite3_column_text(i32* %3, i32 1)
%21 = inttoptr i64 %20 to i8*
%22 = tail call i64 @sqlite3_column_text(i32* %3, i32 2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %17
%25 = tail call i64 @sqlite3_column_text(i32* %3, i32 2)
%26 = inttoptr i64 %25 to i8*
br label %27
27: ; preds = %17, %24
%28 = phi i8* [ %26, %24 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0), %17 ]
%29 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %19, i8* %21, i8* %28)
%30 = tail call i32 @sqlite3_step(i32* %3)
%31 = load i32, i32* @SQLITE_ROW
%32 = icmp eq i32 %30, %31
br i1 %32, label %17, label %33
33: ; preds = %27, %12
%34 = phi i32 [ %14, %12 ], [ %30, %27 ]
%35 = tail call i32 @sqlite3_finalize(i32* %3)
%36 = load i32, i32* @SQLITE_DONE
%37 = icmp eq i32 %34, %36
%38 = select i1 %37, i32 0, i32 %34
br label %39
39: ; preds = %2, %33, %10
%40 = phi i32 [ 3, %10 ], [ %38, %33 ], [ 2, %2 ]
ret i32 %40
}