#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 */
#define SQLITE_DONE 130
#define SQLITE_OK 129
#define SQLITE_ROW 128
char *common_strdup(char *);
int /*<<< orphan*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logprintf(int, char *, ...);
scalar_t__ sqlite3_bind_int(int /*<<< orphan*/ *, int, long);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
long sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_exec(int /*<<< orphan*/ *, char *,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
scalar_t__ sqlite_add_address_order(int /*<<< orphan*/ *, char *, long, char *,
                                    char *);
scalar_t__ sqlite_delete_address(int /*<<< orphan*/ *, long);
int sqlite_swap(sqlite3 *db, long first, long second) {
  int status = 0;
  char *expression = NULL;
  char *router = NULL;
  char *route = NULL;
  logprintf(3, "order1: %d, order2: %d\n", first, second);
  sqlite3_stmt *fetch = database_prepare(
      db, "SELECT address_expression, address_router, address_route FROM "
          "addresses WHERE address_order = ?;");
  sqlite3_stmt *update = database_prepare(
      db, "UPDATE addresses SET address_order = ? WHERE address_order = ?;");
  if (!fetch || !update || sqlite3_bind_int(fetch, 1, first)) {
    logprintf(0, "Failed to prepare or bind statement\n");
    return -1;
  }
  switch (sqlite3_step(fetch)) {
  case SQLITE_ROW:
    expression = common_strdup((char *)sqlite3_column_text(fetch, 0));
    router = common_strdup((char *)sqlite3_column_text(fetch, 1));
    if (sqlite3_column_text(fetch, 2)) {
      route = common_strdup((char *)sqlite3_column_text(fetch, 2));
    }
    if (!expression || !router) {
      status = 19;
    }
    break;
  case SQLITE_DONE:
    logprintf(0, "No expression with order %d\n", first);
    status = 20;
    break;
  default:
    logprintf(0, "Unhandled failure: %s\n", sqlite3_errmsg(db));
    break;
  }
  sqlite3_finalize(fetch);
  if (!status) {
    sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL);
    if (sqlite_delete_address(db, first) != 0) {
      status = 21;
    }
    if (!status && (sqlite3_bind_int(update, 1, first) != SQLITE_OK ||
                    sqlite3_bind_int(update, 2, second) != SQLITE_OK)) {
      status = 22;
    }
    switch (sqlite3_step(update)) {
    case SQLITE_DONE:
    case SQLITE_OK:
      break;
    default:
      logprintf(0, "Failed to update address record: %s\n", sqlite3_errmsg(db));
      status = 23;
      break;
    }
    if (!status &&
        sqlite_add_address_order(db, expression, second, router, route) != 0) {
      status = 24;
    }
    if (status) {
      sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
    } else {
      sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
    }
  }
  sqlite3_finalize(update);
  if (expression) {
    free(expression);
  }
  if (router) {
    free(router);
  }
  if (route) {
    free(route);
  }
  return status;
}


x86 assembly (clang, -O0):
<sqlite_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x3,%edi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   10e0 <logprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   10b0 <database_prepare@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   10b0 <database_prepare@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1268 <sqlite_swap+0xa8>
cmpq   $0x0,-0x50(%rbp)
je     1268 <sqlite_swap+0xa8>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1,%esi
call   1060 <sqlite3_bind_int@plt>
cmp    $0x0,%rax
je     1284 <sqlite_swap+0xc4>
xor    %edi,%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   10e0 <logprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    151c <sqlite_swap+0x35c>
mov    -0x48(%rbp),%rdi
call   1090 <sqlite3_step@plt>
mov    %eax,%ecx
mov    %ecx,-0x54(%rbp)
sub    $0x80,%eax
je     12b5 <sqlite_swap+0xf5>
jmp    12a2 <sqlite_swap+0xe2>
mov    -0x54(%rbp),%eax
sub    $0x82,%eax
je     133a <sqlite_swap+0x17a>
jmp    135a <sqlite_swap+0x19a>
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   1080 <common_strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x1,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   1080 <common_strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x2,%esi
call   10c0 <sqlite3_column_text@plt>
cmp    $0x0,%rax
je     1318 <sqlite_swap+0x158>
mov    -0x48(%rbp),%rdi
mov    $0x2,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   1080 <common_strdup@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     132e <sqlite_swap+0x16e>
cmpq   $0x0,-0x38(%rbp)
jne    1335 <sqlite_swap+0x175>
movl   $0x13,-0x24(%rbp)
jmp    1376 <sqlite_swap+0x1b6>
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   10e0 <logprintf@plt>
movl   $0x14,-0x24(%rbp)
jmp    1376 <sqlite_swap+0x1b6>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    %rax,%rdx
xor    %edi,%edi
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   10e0 <logprintf@plt>
mov    -0x48(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
cmpl   $0x0,-0x24(%rbp)
jne    14d1 <sqlite_swap+0x311>
mov    -0x10(%rbp),%rdi
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <sqlite3_exec@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <sqlite_delete_address@plt>
cmp    $0x0,%rax
je     13c2 <sqlite_swap+0x202>
movl   $0x15,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    140f <sqlite_swap+0x24f>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1,%esi
call   1060 <sqlite3_bind_int@plt>
cmp    $0x81,%rax
jne    1408 <sqlite_swap+0x248>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x2,%esi
call   1060 <sqlite3_bind_int@plt>
cmp    $0x81,%rax
je     140f <sqlite_swap+0x24f>
movl   $0x16,-0x24(%rbp)
mov    -0x50(%rbp),%rdi
call   1090 <sqlite3_step@plt>
add    $0xffffff7f,%eax
sub    $0x1,%eax
ja     1430 <sqlite_swap+0x270>
jmp    142b <sqlite_swap+0x26b>
jmp    1453 <sqlite_swap+0x293>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_errmsg@plt>
mov    %rax,%rdx
xor    %edi,%edi
lea    0xcdf(%rip),%rsi
mov    $0x0,%al
call   10e0 <logprintf@plt>
movl   $0x17,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1487 <sqlite_swap+0x2c7>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   1030 <sqlite_add_address_order@plt>
cmp    $0x0,%rax
je     1487 <sqlite_swap+0x2c7>
movl   $0x18,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     14b1 <sqlite_swap+0x2f1>
mov    -0x10(%rbp),%rdi
lea    0xcad(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <sqlite3_exec@plt>
jmp    14cc <sqlite_swap+0x30c>
mov    -0x10(%rbp),%rdi
lea    0xc96(%rip),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <sqlite3_exec@plt>
jmp    14d1 <sqlite_swap+0x311>
mov    -0x50(%rbp),%rdi
call   10d0 <sqlite3_finalize@plt>
cmpq   $0x0,-0x30(%rbp)
je     14ee <sqlite_swap+0x32e>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1502 <sqlite_swap+0x342>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x40(%rbp)
je     1516 <sqlite_swap+0x356>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_swap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe22(%rip),%rsi
mov    $0x3,%edi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   10e0 <logprintf@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <database_prepare@plt>
mov    %rax,%rbp
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <database_prepare@plt>
test   %rbp,%rbp
je     1233 <sqlite_swap+0x73>
mov    %rax,%r14
test   %rax,%rax
je     1233 <sqlite_swap+0x73>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1060 <sqlite3_bind_int@plt>
test   %rax,%rax
je     1259 <sqlite_swap+0x99>
lea    0xe7f(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   10e0 <logprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1090 <sqlite3_step@plt>
cmp    $0x82,%eax
je     12cb <sqlite_swap+0x10b>
cmp    $0x80,%eax
jne    12f8 <sqlite_swap+0x138>
mov    %rbp,%rdi
xor    %esi,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   1080 <common_strdup@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    $0x1,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   1080 <common_strdup@plt>
mov    %rax,0x10(%rsp)
mov    %rbp,%rdi
mov    $0x2,%esi
call   10c0 <sqlite3_column_text@plt>
test   %rax,%rax
je     132e <sqlite_swap+0x16e>
mov    %rbp,%rdi
mov    $0x2,%esi
call   10c0 <sqlite3_column_text@plt>
mov    %rax,%rdi
call   1080 <common_strdup@plt>
jmp    1330 <sqlite_swap+0x170>
lea    0xe0c(%rip),%rsi
xor    %edi,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   10e0 <logprintf@plt>
mov    %rbp,%rdi
call   10d0 <sqlite3_finalize@plt>
mov    %r14,%rdi
call   10d0 <sqlite3_finalize@plt>
mov    $0x14,%ebp
jmp    1248 <sqlite_swap+0x88>
mov    %rbx,%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xdf4(%rip),%rsi
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
xor    %edi,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10e0 <logprintf@plt>
mov    %rbp,%rdi
call   10d0 <sqlite3_finalize@plt>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
jmp    1357 <sqlite_swap+0x197>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %rbp,%rdi
call   10d0 <sqlite3_finalize@plt>
mov    $0x13,%ebp
test   %r13,%r13
je     144e <sqlite_swap+0x28e>
cmpq   $0x0,0x10(%rsp)
je     144e <sqlite_swap+0x28e>
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <sqlite3_exec@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <sqlite_delete_address@plt>
mov    $0x15,%ebp
test   %rax,%rax
jne    1406 <sqlite_swap+0x246>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1060 <sqlite3_bind_int@plt>
mov    $0x16,%ebp
cmp    $0x81,%rax
jne    1406 <sqlite_swap+0x246>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
call   1060 <sqlite3_bind_int@plt>
cmp    $0x81,%rax
jne    1406 <sqlite_swap+0x246>
mov    %r14,%rdi
call   1090 <sqlite3_step@plt>
add    $0xffffff7f,%eax
cmp    $0x2,%eax
jae    1418 <sqlite_swap+0x258>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%r8
call   1030 <sqlite_add_address_order@plt>
xor    %ecx,%ecx
test   %rax,%rax
lea    0xd61(%rip),%rax
lea    0xd51(%rip),%rsi
cmove  %rax,%rsi
mov    $0x18,%ebp
cmove  %ecx,%ebp
jmp    143f <sqlite_swap+0x27f>
mov    %r14,%rdi
call   1090 <sqlite3_step@plt>
add    $0xffffff7f,%eax
cmp    $0x2,%eax
jb     1438 <sqlite_swap+0x278>
mov    %rbx,%rdi
call   1070 <sqlite3_errmsg@plt>
lea    0xcfd(%rip),%rsi
xor    %edi,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10e0 <logprintf@plt>
mov    $0x17,%ebp
lea    0xd0a(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <sqlite3_exec@plt>
mov    %r14,%rdi
call   10d0 <sqlite3_finalize@plt>
test   %r13,%r13
je     1463 <sqlite_swap+0x2a3>
mov    %r13,%rdi
call   1040 <free@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1472 <sqlite_swap+0x2b2>
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1248 <sqlite_swap+0x88>
call   1040 <free@plt>
jmp    1248 <sqlite_swap+0x88>

LLVM IR (-O0):
@.str = [24 x i8] c"order1: %d, order2: %d\0A\00"
@.str.1 = [97 x i8] c"SELECT address_expression, address_router, address_route FROM addresses WHERE address_order = ?;\00"
@.str.2 = [64 x i8] c"UPDATE addresses SET address_order = ? WHERE address_order = ?;\00"
@.str.3 = [37 x i8] c"Failed to prepare or bind statement\0A\00"
@.str.4 = [29 x i8] c"No expression with order %d\0A\00"
@.str.5 = [23 x i8] c"Unhandled failure: %s\0A\00"
@.str.6 = [18 x i8] c"BEGIN TRANSACTION\00"
@.str.7 = [37 x i8] c"Failed to update address record: %s\0A\00"
@.str.8 = [9 x i8] c"ROLLBACK\00"
@.str.9 = [7 x i8] c"COMMIT\00"
define i32 @sqlite_swap(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
%14 = load i64, i64* %6
%15 = load i64, i64* %7
%16 = call i32 (i32, i8*, ...) @logprintf(i32 3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %14, i64 %15)
%17 = load i32*, i32** %5
%18 = call i32* @database_prepare(i32* %17, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %12
%19 = load i32*, i32** %5
%20 = call i32* @database_prepare(i32* %19, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %13
%21 = load i32*, i32** %12
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %31
23: ; preds = %3
%24 = load i32*, i32** %13
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32*, i32** %12
%28 = load i64, i64* %6
%29 = call i64 @sqlite3_bind_int(i32* %27, i32 1, i64 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26, %23, %3
%32 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %147
33: ; preds = %26
%34 = load i32*, i32** %12
%35 = call i32 @sqlite3_step(i32* %34)
switch i32 %35, label %64 [
i32 128, label %36
i32 130, label %61
]
36: ; preds = %33
%37 = load i32*, i32** %12
%38 = call i64 @sqlite3_column_text(i32* %37, i32 0)
%39 = inttoptr i64 %38 to i8*
%40 = call i8* @common_strdup(i8* %39)
store i8* %40, i8** %9
%41 = load i32*, i32** %12
%42 = call i64 @sqlite3_column_text(i32* %41, i32 1)
%43 = inttoptr i64 %42 to i8*
%44 = call i8* @common_strdup(i8* %43)
store i8* %44, i8** %10
%45 = load i32*, i32** %12
%46 = call i64 @sqlite3_column_text(i32* %45, i32 2)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %36
%49 = load i32*, i32** %12
%50 = call i64 @sqlite3_column_text(i32* %49, i32 2)
%51 = inttoptr i64 %50 to i8*
%52 = call i8* @common_strdup(i8* %51)
store i8* %52, i8** %11
br label %53
53: ; preds = %48, %36
%54 = load i8*, i8** %9
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %10
%58 = icmp ne i8* %57, null
br i1 %58, label %60, label %59
59: ; preds = %56, %53
store i32 19, i32* %8
br label %60
60: ; preds = %59, %56
br label %68
61: ; preds = %33
%62 = load i64, i64* %6
%63 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i64 %62)
store i32 20, i32* %8
br label %68
64: ; preds = %33
%65 = load i32*, i32** %5
%66 = call i64 @sqlite3_errmsg(i32* %65)
%67 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %66)
br label %68
68: ; preds = %64, %61, %60
%69 = load i32*, i32** %12
%70 = call i32 @sqlite3_finalize(i32* %69)
%71 = load i32, i32* %8
%72 = icmp ne i32 %71, 0
br i1 %72, label %125, label %73
73: ; preds = %68
%74 = load i32*, i32** %5
%75 = call i32 @sqlite3_exec(i32* %74, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32* null, i32* null, i32* null)
%76 = load i32*, i32** %5
%77 = load i64, i64* %6
%78 = call i64 @sqlite_delete_address(i32* %76, i64 %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %73
store i32 21, i32* %8
br label %81
81: ; preds = %80, %73
%82 = load i32, i32* %8
%83 = icmp ne i32 %82, 0
br i1 %83, label %95, label %84
84: ; preds = %81
%85 = load i32*, i32** %13
%86 = load i64, i64* %6
%87 = call i64 @sqlite3_bind_int(i32* %85, i32 1, i64 %86)
%88 = icmp ne i64 %87, 129
br i1 %88, label %94, label %89
89: ; preds = %84
%90 = load i32*, i32** %13
%91 = load i64, i64* %7
%92 = call i64 @sqlite3_bind_int(i32* %90, i32 2, i64 %91)
%93 = icmp ne i64 %92, 129
br i1 %93, label %94, label %95
94: ; preds = %89, %84
store i32 22, i32* %8
br label %95
95: ; preds = %94, %89, %81
%96 = load i32*, i32** %13
%97 = call i32 @sqlite3_step(i32* %96)
switch i32 %97, label %99 [
i32 130, label %98
i32 129, label %98
]
98: ; preds = %95, %95
br label %103
99: ; preds = %95
%100 = load i32*, i32** %5
%101 = call i64 @sqlite3_errmsg(i32* %100)
%102 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i64 %101)
store i32 23, i32* %8
br label %103
103: ; preds = %99, %98
%104 = load i32, i32* %8
%105 = icmp ne i32 %104, 0
br i1 %105, label %115, label %106
106: ; preds = %103
%107 = load i32*, i32** %5
%108 = load i8*, i8** %9
%109 = load i64, i64* %7
%110 = load i8*, i8** %10
%111 = load i8*, i8** %11
%112 = call i64 @sqlite_add_address_order(i32* %107, i8* %108, i64 %109, i8* %110, i8* %111)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %115
114: ; preds = %106
store i32 24, i32* %8
br label %115
115: ; preds = %114, %106, %103
%116 = load i32, i32* %8
%117 = icmp ne i32 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %115
%119 = load i32*, i32** %5
%120 = call i32 @sqlite3_exec(i32* %119, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32* null, i32* null, i32* null)
br label %124
121: ; preds = %115
%122 = load i32*, i32** %5
%123 = call i32 @sqlite3_exec(i32* %122, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32* null, i32* null, i32* null)
br label %124
124: ; preds = %121, %118
br label %125
125: ; preds = %124, %68
%126 = load i32*, i32** %13
%127 = call i32 @sqlite3_finalize(i32* %126)
%128 = load i8*, i8** %9
%129 = icmp ne i8* %128, null
br i1 %129, label %130, label %133
130: ; preds = %125
%131 = load i8*, i8** %9
%132 = call i32 @free(i8* %131)
br label %133
133: ; preds = %130, %125
%134 = load i8*, i8** %10
%135 = icmp ne i8* %134, null
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i8*, i8** %10
%138 = call i32 @free(i8* %137)
br label %139
139: ; preds = %136, %133
%140 = load i8*, i8** %11
%141 = icmp ne i8* %140, null
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i8*, i8** %11
%144 = call i32 @free(i8* %143)
br label %145
145: ; preds = %142, %139
%146 = load i32, i32* %8
store i32 %146, i32* %4
br label %147
147: ; preds = %145, %31
%148 = load i32, i32* %4
ret i32 %148
}

LLVM IR (-O2):
@.str = [24 x i8] c"order1: %d, order2: %d\0A\00"
@.str.1 = [97 x i8] c"SELECT address_expression, address_router, address_route FROM addresses WHERE address_order = ?;\00"
@.str.2 = [64 x i8] c"UPDATE addresses SET address_order = ? WHERE address_order = ?;\00"
@.str.3 = [37 x i8] c"Failed to prepare or bind statement\0A\00"
@.str.4 = [29 x i8] c"No expression with order %d\0A\00"
@.str.5 = [23 x i8] c"Unhandled failure: %s\0A\00"
@.str.6 = [18 x i8] c"BEGIN TRANSACTION\00"
@.str.7 = [37 x i8] c"Failed to update address record: %s\0A\00"
@.str.8 = [9 x i8] c"ROLLBACK\00"
@.str.9 = [7 x i8] c"COMMIT\00"
define i32 @sqlite_swap(i32* %0, i64 %1, i64 %2) {
%4 = tail call i32 (i32, i8*, ...) @logprintf(i32 3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %1, i64 %2)
%5 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp ne i32* %5, null
%8 = icmp ne i32* %6, null
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i64 @sqlite3_bind_int(i32* %5, i32 1, i64 %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10, %3
%14 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %95
15: ; preds = %10
%16 = tail call i32 @sqlite3_step(i32* %5)
switch i32 %16, label %34 [
i32 128, label %17
i32 130, label %30
]
17: ; preds = %15
%18 = tail call i64 @sqlite3_column_text(i32* %5, i32 0)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i8* @common_strdup(i8* %19)
%21 = tail call i64 @sqlite3_column_text(i32* %5, i32 1)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i8* @common_strdup(i8* %22)
%24 = tail call i64 @sqlite3_column_text(i32* %5, i32 2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %17
%27 = tail call i64 @sqlite3_column_text(i32* %5, i32 2)
%28 = inttoptr i64 %27 to i8*
%29 = tail call i8* @common_strdup(i8* %28)
br label %38
30: ; preds = %15
%31 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i64 %1)
%32 = tail call i32 @sqlite3_finalize(i32* %5)
%33 = tail call i32 @sqlite3_finalize(i32* %6)
br label %95
34: ; preds = %15
%35 = tail call i64 @sqlite3_errmsg(i32* %0)
%36 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %35)
%37 = tail call i32 @sqlite3_finalize(i32* %5)
br label %44
38: ; preds = %17, %26
%39 = phi i8* [ %29, %26 ], [ null, %17 ]
%40 = icmp ne i8* %20, null
%41 = icmp ne i8* %23, null
%42 = select i1 %40, i1 %41, i1 false
%43 = tail call i32 @sqlite3_finalize(i32* %5)
br i1 %42, label %44, label %78
44: ; preds = %34, %38
%45 = phi i8* [ null, %34 ], [ %39, %38 ]
%46 = phi i8* [ null, %34 ], [ %23, %38 ]
%47 = phi i8* [ null, %34 ], [ %20, %38 ]
%48 = tail call i32 @sqlite3_exec(i32* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32* null, i32* null, i32* null)
%49 = tail call i64 @sqlite_delete_address(i32* %0, i64 %1)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %44
%52 = tail call i64 @sqlite3_bind_int(i32* %6, i32 1, i64 %1)
%53 = icmp eq i64 %52, 129
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = tail call i64 @sqlite3_bind_int(i32* %6, i32 2, i64 %2)
%56 = icmp eq i64 %55, 129
br i1 %56, label %62, label %57
57: ; preds = %51, %54, %44
%58 = phi i32 [ 21, %44 ], [ 22, %54 ], [ 22, %51 ]
%59 = tail call i32 @sqlite3_step(i32* %6)
%60 = add i32 %59, -129
%61 = icmp ult i32 %60, 2
br i1 %61, label %74, label %66
62: ; preds = %54
%63 = tail call i32 @sqlite3_step(i32* %6)
%64 = add i32 %63, -129
%65 = icmp ult i32 %64, 2
br i1 %65, label %69, label %66
66: ; preds = %62, %57
%67 = tail call i64 @sqlite3_errmsg(i32* %0)
%68 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i64 %67)
br label %74
69: ; preds = %62
%70 = tail call i64 @sqlite_add_address_order(i32* %0, i8* %47, i64 %2, i8* %46, i8* %45)
%71 = icmp eq i64 %70, 0
%72 = select i1 %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0)
%73 = select i1 %71, i32 0, i32 24
br label %74
74: ; preds = %69, %66, %57
%75 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), %57 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), %66 ], [ %72, %69 ]
%76 = phi i32 [ %58, %57 ], [ 23, %66 ], [ %73, %69 ]
%77 = tail call i32 @sqlite3_exec(i32* %0, i8* %75, i32* null, i32* null, i32* null)
br label %78
78: ; preds = %74, %38
%79 = phi i8* [ %39, %38 ], [ %45, %74 ]
%80 = phi i8* [ %23, %38 ], [ %46, %74 ]
%81 = phi i8* [ %20, %38 ], [ %47, %74 ]
%82 = phi i32 [ 19, %38 ], [ %76, %74 ]
%83 = tail call i32 @sqlite3_finalize(i32* %6)
%84 = icmp eq i8* %81, null
br i1 %84, label %87, label %85
85: ; preds = %78
%86 = tail call i32 @free(i8* %81)
br label %87
87: ; preds = %85, %78
%88 = icmp eq i8* %80, null
br i1 %88, label %91, label %89
89: ; preds = %87
%90 = tail call i32 @free(i8* %80)
br label %91
91: ; preds = %89, %87
%92 = icmp eq i8* %79, null
br i1 %92, label %95, label %93
93: ; preds = %91
%94 = tail call i32 @free(i8* %79)
br label %95
95: ; preds = %30, %91, %93, %13
%96 = phi i32 [ -1, %13 ], [ %82, %93 ], [ %82, %91 ], [ 20, %30 ]
ret i32 %96
}