#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_update_address(sqlite3 *db, long order, const char *router,
                          const char *route) {
  char *sql = "UPDATE addresses SET address_router = ?, address_route = ? "
              "WHERE address_order = ?";
  int rv = 0;
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, router, -1, SQLITE_STATIC) != SQLITE_OK ||
      sqlite3_bind_int(stmt, 3, order) != SQLITE_OK ||
      sqlite3_bind_text(stmt, 2, route, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Failed to bind a statement parameters\n\n");
    sqlite3_finalize(stmt);
    return 3;
  }
  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_update_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    0xe71(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <database_prepare@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11c2 <sqlite_update_address+0x52>
movl   $0x2,-0x4(%rbp)
jmp    12b5 <sqlite_update_address+0x145>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2e07(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
jne    1246 <sqlite_update_address+0xd6>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3,%esi
call   1030 <sqlite3_bind_int@plt>
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
jne    1246 <sqlite_update_address+0xd6>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x2db4(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%rax
je     126b <sqlite_update_address+0xfb>
xor    %edi,%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1090 <logprintf@plt>
mov    -0x40(%rbp),%rdi
call   1080 <sqlite3_finalize@plt>
movl   $0x3,-0x4(%rbp)
jmp    12b5 <sqlite_update_address+0x145>
mov    -0x40(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%rax
je     12a6 <sqlite_update_address+0x136>
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1090 <logprintf@plt>
movl   $0x5,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
call   1080 <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_update_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xe72(%rip),%rsi
call   1060 <database_prepare@plt>
test   %rax,%rax
je     1257 <sqlite_update_address+0xe7>
mov    %rax,%rbx
mov    0x2e32(%rip),%r13
mov    0x0(%r13),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x2e22(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1238 <sqlite_update_address+0xc8>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r12,%rdx
call   1030 <sqlite3_bind_int@plt>
cmp    0x0(%rbp),%rax
jne    1238 <sqlite_update_address+0xc8>
mov    0x0(%r13),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    1238 <sqlite_update_address+0xc8>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
mov    0x2dc0(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     124d <sqlite_update_address+0xdd>
mov    %r14,%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe55(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <logprintf@plt>
mov    $0x5,%ebp
jmp    124d <sqlite_update_address+0xdd>
lea    0xe14(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1090 <logprintf@plt>
mov    $0x3,%ebp
mov    %rbx,%rdi
call   1080 <sqlite3_finalize@plt>
jmp    125c <sqlite_update_address+0xec>
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 = [83 x i8] c"UPDATE addresses SET address_router = ?, address_route = ? WHERE address_order = ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [40 x i8] c"Failed to bind a statement parameters\0A\0A\00"
@SQLITE_DONE = global i64 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_update_address(i32* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
store i32* %0, i32** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* getelementptr inbounds ([83 x i8], [83 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 %56
19: ; preds = %4
%20 = load i32*, i32** %12
%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 %39, label %26
26: ; preds = %19
%27 = load i32*, i32** %12
%28 = load i64, i64* %7
%29 = call i64 @sqlite3_bind_int(i32* %27, i32 3, i64 %28)
%30 = load i64, i64* @SQLITE_OK
%31 = icmp ne i64 %29, %30
br i1 %31, label %39, label %32
32: ; preds = %26
%33 = load i32*, i32** %12
%34 = load i8*, i8** %9
%35 = load i32, i32* @SQLITE_STATIC
%36 = call i64 @sqlite3_bind_text(i32* %33, i32 2, i8* %34, i32 -1, i32 %35)
%37 = load i64, i64* @SQLITE_OK
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %32, %26, %19
%40 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32*, i32** %12
%42 = call i32 @sqlite3_finalize(i32* %41)
store i32 3, i32* %5
br label %56
43: ; preds = %32
%44 = load i32*, i32** %12
%45 = call i64 @sqlite3_step(i32* %44)
%46 = load i64, i64* @SQLITE_DONE
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i32*, i32** %6
%50 = call i32 @sqlite3_errmsg(i32* %49)
%51 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %50)
store i32 5, i32* %11
br label %52
52: ; preds = %48, %43
%53 = load i32*, i32** %12
%54 = call i32 @sqlite3_finalize(i32* %53)
%55 = load i32, i32* %11
store i32 %55, i32* %5
br label %56
56: ; preds = %52, %39, %18
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
@.str = [83 x i8] c"UPDATE addresses SET address_router = ?, address_route = ? WHERE address_order = ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [40 x i8] c"Failed to bind a statement parameters\0A\0A\00"
@SQLITE_DONE = global i64 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_update_address(i32* %0, i64 %1, i8* %2, i8* %3) {
%5 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %33, 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 %21
12: ; preds = %7
%13 = tail call i64 @sqlite3_bind_int(i32* %5, i32 3, i64 %1)
%14 = load i64, i64* @SQLITE_OK
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* @SQLITE_STATIC
%18 = tail call i64 @sqlite3_bind_text(i32* %5, i32 2, i8* %3, i32 -1, i32 %17)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp eq i64 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %16, %12, %7
%22 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %30
23: ; preds = %16
%24 = tail call i64 @sqlite3_step(i32* %5)
%25 = load i64, i64* @SQLITE_DONE
%26 = icmp eq i64 %24, %25
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = tail call i32 @sqlite3_errmsg(i32* %0)
%29 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %23, %27, %21
%31 = phi i32 [ 3, %21 ], [ 5, %27 ], [ 0, %23 ]
%32 = tail call i32 @sqlite3_finalize(i32* %5)
br label %33
33: ; preds = %30, %4
%34 = phi i32 [ 2, %4 ], [ %31, %30 ]
ret i32 %34
}