#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 */
scalar_t__ SQLITE_DONE;
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ logprintf(int, char *, ...);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int sqlite_add_msa(sqlite3 *db, const char *user, const char *router,
                   const char *argument) {
  char *sql = router ? "INSERT INTO smtpd (smtpd_user, smtpd_router, "
                       "smtpd_route) VALUES (?, ?, ?);"
                     : "INSERT INTO smtpd (smtpd_user) VALUES (?);";
  logprintf(3, "Using statement %s\n", sql);
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, user, -1, SQLITE_STATIC) != SQLITE_OK ||
      (router &&
       sqlite3_bind_text(stmt, 2, router, -1, SQLITE_STATIC) != SQLITE_OK) ||
      (router &&
       sqlite3_bind_text(stmt, 3, argument, -1, SQLITE_STATIC) != SQLITE_OK)) {
    logprintf(0, "Failed to bind a statement parameter\n");
    sqlite3_finalize(stmt);
    return 3;
  }
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    logprintf(0, "%s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    return 5;
  }
  sqlite3_finalize(stmt);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_add_msa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdx
lea    0xec9(%rip),%rax
lea    0xe76(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
mov    $0x3,%edi
lea    0xed1(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <database_prepare@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d5 <sqlite_add_msa+0x75>
movl   $0x2,-0x4(%rbp)
jmp    12fd <sqlite_add_msa+0x19d>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2df4(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
jne    127e <sqlite_add_msa+0x11e>
cmpq   $0x0,-0x20(%rbp)
je     1242 <sqlite_add_msa+0xe2>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2db8(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    127e <sqlite_add_msa+0x11e>
cmpq   $0x0,-0x20(%rbp)
je     12a3 <sqlite_add_msa+0x143>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2d7c(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2d73(%rip),%rcx
cmp    (%rcx),%rax
je     12a3 <sqlite_add_msa+0x143>
xor    %edi,%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x3,-0x4(%rbp)
jmp    12fd <sqlite_add_msa+0x19d>
mov    -0x38(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2d1d(%rip),%rcx
cmp    (%rcx),%rax
je     12ed <sqlite_add_msa+0x18d>
mov    -0x10(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    %rax,%rdx
xor    %edi,%edi
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x5,-0x4(%rbp)
jmp    12fd <sqlite_add_msa+0x19d>
mov    -0x38(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_add_msa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %rdi,%r14
test   %rdx,%rdx
lea    0xecb(%rip),%rax
lea    0xe78(%rip),%rbx
cmove  %rax,%rbx
lea    0xee4(%rip),%rsi
mov    $0x3,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <database_prepare@plt>
test   %rax,%rax
je     127f <sqlite_add_msa+0x11f>
mov    %rax,%r12
mov    %r15,(%rsp)
mov    0x2e14(%rip),%r15
mov    (%r15),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e05(%rip),%rbx
cmp    (%rbx),%rax
jne    1260 <sqlite_add_msa+0x100>
test   %rbp,%rbp
je     1228 <sqlite_add_msa+0xc8>
mov    (%r15),%r8d
mov    %r12,%rdi
mov    $0x2,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
cmp    (%rbx),%rax
jne    1260 <sqlite_add_msa+0x100>
mov    (%r15),%r8d
mov    %r12,%rdi
mov    $0x3,%esi
mov    (%rsp),%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
cmp    (%rbx),%rax
jne    1260 <sqlite_add_msa+0x100>
mov    %r12,%rdi
call   1040 <sqlite3_step@plt>
mov    0x2d99(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     1275 <sqlite_add_msa+0x115>
mov    %r14,%rdi
call   1030 <sqlite3_errmsg@plt>
lea    0xe3a(%rip),%rsi
xor    %edi,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x5,%ebx
jmp    1275 <sqlite_add_msa+0x115>
lea    0xe24(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x3,%ebx
mov    %r12,%rdi
call   1070 <sqlite3_finalize@plt>
jmp    1284 <sqlite_add_msa+0x124>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [76 x i8] c"INSERT INTO smtpd (smtpd_user, smtpd_router, smtpd_route) VALUES (?, ?, ?);\00"
@.str.1 = [43 x i8] c"INSERT INTO smtpd (smtpd_user) VALUES (?);\00"
@.str.2 = [20 x i8] c"Using statement %s\0A\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.3 = [38 x i8] c"Failed to bind a statement parameter\0A\00"
@SQLITE_DONE = global i64 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_add_msa(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0)
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = call i32 (i32, i8*, ...) @logprintf(i32 3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %6
%19 = load i8*, i8** %10
%20 = call i32* @database_prepare(i32* %18, i8* %19)
store i32* %20, i32** %11
%21 = load i32*, i32** %11
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %4
store i32 2, i32* %5
br label %69
24: ; preds = %4
%25 = load i32*, i32** %11
%26 = load i8*, i8** %7
%27 = load i32, i32* @SQLITE_STATIC
%28 = call i64 @sqlite3_bind_text(i32* %25, i32 1, i8* %26, i32 -1, i32 %27)
%29 = load i64, i64* @SQLITE_OK
%30 = icmp ne i64 %28, %29
br i1 %30, label %51, label %31
31: ; preds = %24
%32 = load i8*, i8** %8
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32*, i32** %11
%36 = load i8*, i8** %8
%37 = load i32, i32* @SQLITE_STATIC
%38 = call i64 @sqlite3_bind_text(i32* %35, i32 2, i8* %36, i32 -1, i32 %37)
%39 = load i64, i64* @SQLITE_OK
%40 = icmp ne i64 %38, %39
br i1 %40, label %51, label %41
41: ; preds = %34, %31
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %55
44: ; preds = %41
%45 = load i32*, i32** %11
%46 = load i8*, i8** %9
%47 = load i32, i32* @SQLITE_STATIC
%48 = call i64 @sqlite3_bind_text(i32* %45, i32 3, i8* %46, i32 -1, i32 %47)
%49 = load i64, i64* @SQLITE_OK
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %44, %34, %24
%52 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32*, i32** %11
%54 = call i32 @sqlite3_finalize(i32* %53)
store i32 3, i32* %5
br label %69
55: ; preds = %44, %41
%56 = load i32*, i32** %11
%57 = call i64 @sqlite3_step(i32* %56)
%58 = load i64, i64* @SQLITE_DONE
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %66
60: ; preds = %55
%61 = load i32*, i32** %6
%62 = call i8* @sqlite3_errmsg(i32* %61)
%63 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %62)
%64 = load i32*, i32** %11
%65 = call i32 @sqlite3_finalize(i32* %64)
store i32 5, i32* %5
br label %69
66: ; preds = %55
%67 = load i32*, i32** %11
%68 = call i32 @sqlite3_finalize(i32* %67)
store i32 0, i32* %5
br label %69
69: ; preds = %66, %60, %51, %23
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
@.str = [76 x i8] c"INSERT INTO smtpd (smtpd_user, smtpd_router, smtpd_route) VALUES (?, ?, ?);\00"
@.str.1 = [43 x i8] c"INSERT INTO smtpd (smtpd_user) VALUES (?);\00"
@.str.2 = [20 x i8] c"Using statement %s\0A\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.3 = [38 x i8] c"Failed to bind a statement parameter\0A\00"
@SQLITE_DONE = global i64 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_add_msa(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %2, null
%6 = select i1 %5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0)
%7 = tail call i32 (i32, i8*, ...) @logprintf(i32 3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = tail call i32* @database_prepare(i32* %0, i8* %6)
%9 = icmp eq i32* %8, null
br i1 %9, label %38, label %10
10: ; preds = %4
%11 = load i32, i32* @SQLITE_STATIC
%12 = tail call i64 @sqlite3_bind_text(i32* %8, i32 1, i8* %1, i32 -1, i32 %11)
%13 = load i64, i64* @SQLITE_OK
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %10
br i1 %5, label %28, label %16
16: ; preds = %15
%17 = load i32, i32* @SQLITE_STATIC
%18 = tail call i64 @sqlite3_bind_text(i32* %8, i32 2, i8* %2, i32 -1, i32 %17)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @SQLITE_STATIC
%23 = tail call i64 @sqlite3_bind_text(i32* %8, i32 3, i8* %3, i32 -1, i32 %22)
%24 = load i64, i64* @SQLITE_OK
%25 = icmp eq i64 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %21, %16, %10
%27 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %35
28: ; preds = %15, %21
%29 = tail call i64 @sqlite3_step(i32* %8)
%30 = load i64, i64* @SQLITE_DONE
%31 = icmp eq i64 %29, %30
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = tail call i8* @sqlite3_errmsg(i32* %0)
%34 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %28, %26, %32
%36 = phi i32 [ 5, %32 ], [ 3, %26 ], [ 0, %28 ]
%37 = tail call i32 @sqlite3_finalize(i32* %8)
br label %38
38: ; preds = %35, %4
%39 = phi i32 [ 2, %4 ], [ %36, %35 ]
ret i32 %39
}