#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 /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
int sqlite3_changes(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int sqlite_update_msa(sqlite3 *db, const char *user, const char *router,
                      const char *argument) {
  char *sql = "UPDATE smtpd SET smtpd_router = ?, smtpd_route = ? WHERE "
              "smtpd_user = ?;";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  int rv = 0;
  if (sqlite3_bind_text(stmt, 1, router, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_text(stmt, 2, argument, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_text(stmt, 3, user, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Failed to bind a statement parameter\n\n");
    sqlite3_finalize(stmt);
    return 72;
  }
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    logprintf(0, "%s\n", sqlite3_errmsg(db));
    rv = 5;
  }
  sqlite3_finalize(stmt);
  if (sqlite3_changes(db) < 1) {
    printf("No entry found, no modifications performed\n");
  }
  return rv;
}


x86 assembly (clang, -O0):
<sqlite_update_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)
lea    0xe61(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <database_prepare@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11cb <sqlite_update_msa+0x4b>
movl   $0x2,-0x4(%rbp)
jmp    12f2 <sqlite_update_msa+0x172>
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2df7(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <sqlite_update_msa+0xe5>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2dc6(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <sqlite_update_msa+0xe5>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2d95(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
je     128a <sqlite_update_msa+0x10a>
xor    %edi,%edi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
mov    -0x38(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x48,-0x4(%rbp)
jmp    12f2 <sqlite_update_msa+0x172>
mov    -0x38(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d36(%rip),%rcx
cmp    (%rcx),%rax
je     12c5 <sqlite_update_msa+0x145>
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
movl   $0x5,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_changes@plt>
cmp    $0x1,%eax
jge    12ec <sqlite_update_msa+0x16c>
lea    0xd8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_update_msa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe62(%rip),%rsi
call   1060 <database_prepare@plt>
test   %rax,%rax
je     1294 <sqlite_update_msa+0x114>
mov    %rax,%rbx
mov    0x2e22(%rip),%r13
mov    0x0(%r13),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2e12(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1275 <sqlite_update_msa+0xf5>
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    1275 <sqlite_update_msa+0xf5>
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    1275 <sqlite_update_msa+0xf5>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
mov    0x2da3(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     1253 <sqlite_update_msa+0xd3>
mov    %r14,%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe2d(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <logprintf@plt>
mov    $0x5,%ebp
mov    %rbx,%rdi
call   1090 <sqlite3_finalize@plt>
mov    %r14,%rdi
call   1070 <sqlite3_changes@plt>
test   %eax,%eax
jg     1299 <sqlite_update_msa+0x119>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
jmp    1299 <sqlite_update_msa+0x119>
lea    0xdcd(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   10a0 <logprintf@plt>
mov    %rbx,%rdi
call   1090 <sqlite3_finalize@plt>
mov    $0x48,%ebp
jmp    1299 <sqlite_update_msa+0x119>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [73 x i8] c"UPDATE smtpd SET smtpd_router = ?, smtpd_route = ? WHERE smtpd_user = ?;\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [39 x i8] c"Failed to bind a statement parameter\0A\0A\00"
@SQLITE_DONE = global i64 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [44 x i8] c"No entry found, no modifications performed\0A\00"
define i32 @sqlite_update_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*
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8** %10
%13 = load i32*, i32** %6
%14 = load i8*, i8** %10
%15 = call i32* @database_prepare(i32* %13, i8* %14)
store i32* %15, i32** %11
%16 = load i32*, i32** %11
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %4
store i32 2, i32* %5
br label %63
19: ; preds = %4
store i32 0, i32* %12
%20 = load i32*, i32** %11
%21 = load i8*, i8** %8
%22 = load i32, i32* @SQLITE_STATIC
%23 = call i64 @sqlite3_bind_text(i32* %20, i32 1, i8* %21, i32 -1, i32 %22)
%24 = load i64, i64* @SQLITE_OK
%25 = icmp ne i64 %23, %24
br i1 %25, label %40, label %26
26: ; preds = %19
%27 = load i32*, i32** %11
%28 = load i8*, i8** %9
%29 = load i32, i32* @SQLITE_STATIC
%30 = call i64 @sqlite3_bind_text(i32* %27, i32 2, i8* %28, i32 -1, i32 %29)
%31 = load i64, i64* @SQLITE_OK
%32 = icmp ne i64 %30, %31
br i1 %32, label %40, label %33
33: ; preds = %26
%34 = load i32*, i32** %11
%35 = load i8*, i8** %7
%36 = load i32, i32* @SQLITE_STATIC
%37 = call i64 @sqlite3_bind_text(i32* %34, i32 3, i8* %35, i32 -1, i32 %36)
%38 = load i64, i64* @SQLITE_OK
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %33, %26, %19
%41 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32*, i32** %11
%43 = call i32 @sqlite3_finalize(i32* %42)
store i32 72, i32* %5
br label %63
44: ; preds = %33
%45 = load i32*, i32** %11
%46 = call i64 @sqlite3_step(i32* %45)
%47 = load i64, i64* @SQLITE_DONE
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32*, i32** %6
%51 = call i32 @sqlite3_errmsg(i32* %50)
%52 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %51)
store i32 5, i32* %12
br label %53
53: ; preds = %49, %44
%54 = load i32*, i32** %11
%55 = call i32 @sqlite3_finalize(i32* %54)
%56 = load i32*, i32** %6
%57 = call i32 @sqlite3_changes(i32* %56)
%58 = icmp slt i32 %57, 1
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %53
%62 = load i32, i32* %12
store i32 %62, i32* %5
br label %63
63: ; preds = %61, %40, %18
%64 = load i32, i32* %5
ret i32 %64
}

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