#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_int(int /*<<< orphan*/ *, int, long);
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_order(sqlite3 *db, const char *expression, long order,
                             const char *router, const char *route) {
  char *sql = "INSERT INTO addresses (address_expression, address_order, "
              "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, 3, router, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_text(stmt, 4, route, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_int(stmt, 2, order) != 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_order>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    0xe6d(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <database_prepare@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11c6 <sqlite_add_address_order+0x56>
movl   $0x2,-0x4(%rbp)
jmp    12ea <sqlite_add_address_order+0x17a>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e03(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
jne    127b <sqlite_add_address_order+0x10b>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2dd2(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
jne    127b <sqlite_add_address_order+0x10b>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    0x2da1(%rip),%rax
mov    (%rax),%r8d
mov    $0x4,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
jne    127b <sqlite_add_address_order+0x10b>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x2,%esi
call   1030 <sqlite3_bind_int@plt>
mov    0x2d76(%rip),%rcx
cmp    (%rcx),%rax
je     12a0 <sqlite_add_address_order+0x130>
xor    %edi,%edi
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1090 <logprintf@plt>
mov    -0x48(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
movl   $0x4,-0x4(%rbp)
jmp    12ea <sqlite_add_address_order+0x17a>
mov    -0x48(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d20(%rip),%rcx
cmp    (%rcx),%rax
je     12db <sqlite_add_address_order+0x16b>
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1090 <logprintf@plt>
movl   $0x5,-0x3c(%rbp)
mov    -0x48(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_add_address_order>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe6c(%rip),%rsi
call   1060 <database_prepare@plt>
test   %rax,%rax
je     128b <sqlite_add_address_order+0x11b>
mov    %rax,%r12
mov    %rbp,0x10(%rsp)
mov    %rbx,0x8(%rsp)
mov    0x2e22(%rip),%rbx
mov    (%rbx),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2e13(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    126c <sqlite_add_address_order+0xfc>
mov    (%rbx),%r8d
mov    %r12,%rdi
mov    $0x3,%esi
mov    %r13,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    126c <sqlite_add_address_order+0xfc>
mov    (%rbx),%r8d
mov    %r12,%rdi
mov    $0x4,%esi
mov    0x10(%rsp),%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    126c <sqlite_add_address_order+0xfc>
mov    %r12,%rdi
mov    $0x2,%esi
mov    0x8(%rsp),%rdx
call   1030 <sqlite3_bind_int@plt>
cmp    0x0(%rbp),%rax
jne    126c <sqlite_add_address_order+0xfc>
mov    %r12,%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d8c(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     1281 <sqlite_add_address_order+0x111>
mov    %r14,%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe3a(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <logprintf@plt>
mov    $0x5,%ebp
jmp    1281 <sqlite_add_address_order+0x111>
lea    0xdfa(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1090 <logprintf@plt>
mov    $0x4,%ebp
mov    %r12,%rdi
call   1080 <sqlite3_finalize@plt>
jmp    1290 <sqlite_add_address_order+0x120>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [109 x i8] c"INSERT INTO addresses (address_expression, address_order, 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_order(i32* %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32*
store i32* %0, i32** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str, i64 0, i64 0), i8** %12
store i32 0, i32* %13
%15 = load i32*, i32** %7
%16 = load i8*, i8** %12
%17 = call i32* @database_prepare(i32* %15, i8* %16)
store i32* %17, i32** %14
%18 = load i32*, i32** %14
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %5
store i32 2, i32* %6
br label %65
21: ; preds = %5
%22 = load i32*, i32** %14
%23 = load i8*, i8** %8
%24 = load i32, i32* @SQLITE_STATIC
%25 = call i64 @sqlite3_bind_text(i32* %22, i32 1, i8* %23, i32 -1, i32 %24)
%26 = load i64, i64* @SQLITE_OK
%27 = icmp ne i64 %25, %26
br i1 %27, label %48, label %28
28: ; preds = %21
%29 = load i32*, i32** %14
%30 = load i8*, i8** %10
%31 = load i32, i32* @SQLITE_STATIC
%32 = call i64 @sqlite3_bind_text(i32* %29, i32 3, i8* %30, i32 -1, i32 %31)
%33 = load i64, i64* @SQLITE_OK
%34 = icmp ne i64 %32, %33
br i1 %34, label %48, label %35
35: ; preds = %28
%36 = load i32*, i32** %14
%37 = load i8*, i8** %11
%38 = load i32, i32* @SQLITE_STATIC
%39 = call i64 @sqlite3_bind_text(i32* %36, i32 4, i8* %37, i32 -1, i32 %38)
%40 = load i64, i64* @SQLITE_OK
%41 = icmp ne i64 %39, %40
br i1 %41, label %48, label %42
42: ; preds = %35
%43 = load i32*, i32** %14
%44 = load i64, i64* %9
%45 = call i64 @sqlite3_bind_int(i32* %43, i32 2, i64 %44)
%46 = load i64, i64* @SQLITE_OK
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %52
48: ; preds = %42, %35, %28, %21
%49 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32*, i32** %14
%51 = call i32 @sqlite3_finalize(i32* %50)
store i32 4, i32* %6
br label %65
52: ; preds = %42
%53 = load i32*, i32** %14
%54 = call i64 @sqlite3_step(i32* %53)
%55 = load i64, i64* @SQLITE_DONE
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = load i32*, i32** %7
%59 = call i32 @sqlite3_errmsg(i32* %58)
%60 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %59)
store i32 5, i32* %13
br label %61
61: ; preds = %57, %52
%62 = load i32*, i32** %14
%63 = call i32 @sqlite3_finalize(i32* %62)
%64 = load i32, i32* %13
store i32 %64, i32* %6
br label %65
65: ; preds = %61, %48, %20
%66 = load i32, i32* %6
ret i32 %66
}

LLVM IR (-O2):
@.str = [109 x i8] c"INSERT INTO addresses (address_expression, address_order, 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_order(i32* %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %39, label %8
8: ; preds = %5
%9 = load i32, i32* @SQLITE_STATIC
%10 = tail call i64 @sqlite3_bind_text(i32* %6, i32 1, i8* %1, i32 -1, i32 %9)
%11 = load i64, i64* @SQLITE_OK
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i32, i32* @SQLITE_STATIC
%15 = tail call i64 @sqlite3_bind_text(i32* %6, i32 3, i8* %3, i32 -1, i32 %14)
%16 = load i64, i64* @SQLITE_OK
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* @SQLITE_STATIC
%20 = tail call i64 @sqlite3_bind_text(i32* %6, i32 4, i8* %4, i32 -1, i32 %19)
%21 = load i64, i64* @SQLITE_OK
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = tail call i64 @sqlite3_bind_int(i32* %6, i32 2, i64 %2)
%25 = load i64, i64* @SQLITE_OK
%26 = icmp eq i64 %24, %25
br i1 %26, label %29, label %27
27: ; preds = %23, %18, %13, %8
%28 = 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 %36
29: ; preds = %23
%30 = tail call i64 @sqlite3_step(i32* %6)
%31 = load i64, i64* @SQLITE_DONE
%32 = icmp eq i64 %30, %31
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = tail call i32 @sqlite3_errmsg(i32* %0)
%35 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %29, %33, %27
%37 = phi i32 [ 4, %27 ], [ 5, %33 ], [ 0, %29 ]
%38 = tail call i32 @sqlite3_finalize(i32* %6)
br label %39
39: ; preds = %36, %5
%40 = phi i32 [ 2, %5 ], [ %37, %36 ]
ret i32 %40
}