#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 *, ...);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int sqlite_add_address(sqlite3 *db, const char *expression, const char *router,
                       const char *route) {
  char *sql = "INSERT INTO addresses (address_expression, address_router, "
              "address_route) VALUES (?, ?, ?)";
  int rv = 0;
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, expression, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_text(stmt, 2, router, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_text(stmt, 3, route, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Failed to bind a statement parameter\n\n");
    sqlite3_finalize(stmt);
    return 4;
  }
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    logprintf(0, "%s\n", sqlite3_errmsg(db));
    rv = 5;
  }
  sqlite3_finalize(stmt);
  return rv;
}


x86 assembly (clang, -O0):
<sqlite_add_address>:
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    0xe81(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <database_prepare@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11b2 <sqlite_add_address+0x52>
movl   $0x2,-0x4(%rbp)
jmp    12b4 <sqlite_add_address+0x154>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e17(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
jne    1245 <sqlite_add_address+0xe5>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2de6(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%rax
jne    1245 <sqlite_add_address+0xe5>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2db5(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2dac(%rip),%rcx
cmp    (%rcx),%rax
je     126a <sqlite_add_address+0x10a>
xor    %edi,%edi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x40(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x4,-0x4(%rbp)
jmp    12b4 <sqlite_add_address+0x154>
mov    -0x40(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2d56(%rip),%rcx
cmp    (%rcx),%rax
je     12a5 <sqlite_add_address+0x145>
mov    -0x10(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
movl   $0x5,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_add_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
call   1050 <database_prepare@plt>
test   %rax,%rax
je     1250 <sqlite_add_address+0xf0>
mov    %rax,%rbx
mov    0x2e42(%rip),%r13
mov    0x0(%r13),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e32(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1231 <sqlite_add_address+0xd1>
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    1231 <sqlite_add_address+0xd1>
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    1231 <sqlite_add_address+0xd1>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
mov    0x2dc7(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     1246 <sqlite_add_address+0xe6>
mov    %r14,%rdi
call   1030 <sqlite3_errmsg@plt>
lea    0xe63(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x5,%ebp
jmp    1246 <sqlite_add_address+0xe6>
lea    0xe23(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x4,%ebp
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
jmp    1255 <sqlite_add_address+0xf5>
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 = [91 x i8] c"INSERT INTO addresses (address_expression, address_router, address_route) VALUES (?, ?, ?)\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"
define i32 @sqlite_add_address(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 ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i8** %10
store i32 0, i32* %11
%13 = load i32*, i32** %6
%14 = load i8*, i8** %10
%15 = call i32* @database_prepare(i32* %13, i8* %14)
store i32* %15, i32** %12
%16 = load i32*, i32** %12
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %4
store i32 2, i32* %5
br label %57
19: ; preds = %4
%20 = load i32*, i32** %12
%21 = load i8*, i8** %7
%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** %12
%28 = load i8*, i8** %8
%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** %12
%35 = load i8*, i8** %9
%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** %12
%43 = call i32 @sqlite3_finalize(i32* %42)
store i32 4, i32* %5
br label %57
44: ; preds = %33
%45 = load i32*, i32** %12
%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* %11
br label %53
53: ; preds = %49, %44
%54 = load i32*, i32** %12
%55 = call i32 @sqlite3_finalize(i32* %54)
%56 = load i32, i32* %11
store i32 %56, i32* %5
br label %57
57: ; preds = %53, %40, %18
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@.str = [91 x i8] c"INSERT INTO addresses (address_expression, address_router, address_route) VALUES (?, ?, ?)\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"
define i32 @sqlite_add_address(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %34, label %7
7: ; preds = %4
%8 = load i32, i32* @SQLITE_STATIC
%9 = tail call i64 @sqlite3_bind_text(i32* %5, i32 1, i8* %1, 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* %2, 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* %3, i32 -1, i32 %18)
%20 = load i64, i64* @SQLITE_OK
%21 = icmp eq i64 %19, %20
br i1 %21, label %24, 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))
br label %31
24: ; preds = %17
%25 = tail call i64 @sqlite3_step(i32* %5)
%26 = load i64, i64* @SQLITE_DONE
%27 = icmp eq i64 %25, %26
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = tail call i32 @sqlite3_errmsg(i32* %0)
%30 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %24, %28, %22
%32 = phi i32 [ 4, %22 ], [ 5, %28 ], [ 0, %24 ]
%33 = tail call i32 @sqlite3_finalize(i32* %5)
br label %34
34: ; preds = %31, %4
%35 = phi i32 [ 2, %4 ], [ %32, %31 ]
ret i32 %35
}