#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*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ logprintf(int, char *, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ sqlite3_bind_int(int /*<<< orphan*/ *, int, long);
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_delete_address(sqlite3 *db, long order) {
  char *sql = "DELETE FROM addresses WHERE address_order = ?;";
  int rv = 0;
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_int(stmt, 1, order) == SQLITE_OK) {
    if (sqlite3_step(stmt) != SQLITE_DONE) {
      logprintf(0, "%s\n", sqlite3_errmsg(db));
      rv = 5;
    }
  } else {
    logprintf(1, "Failed to bind a statement parameter\n\n");
    rv = 4;
  }
  if (!rv && sqlite3_changes(db) < 1) {
    printf("No such address, no modifications commited\n");
  }
  sqlite3_finalize(stmt);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_delete_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe69(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <database_prepare@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ca <sqlite_delete_address+0x4a>
movl   $0x2,-0x4(%rbp)
jmp    127e <sqlite_delete_address+0xfe>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
jne    122c <sqlite_delete_address+0xac>
mov    -0x30(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
je     1227 <sqlite_delete_address+0xa7>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
movl   $0x5,-0x24(%rbp)
jmp    1246 <sqlite_delete_address+0xc6>
mov    $0x1,%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
movl   $0x4,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    126e <sqlite_delete_address+0xee>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_changes@plt>
cmp    $0x1,%eax
jge    126e <sqlite_delete_address+0xee>
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_delete_address>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe6e(%rip),%rsi
call   1070 <database_prepare@plt>
test   %rax,%rax
je     11e9 <sqlite_delete_address+0x69>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1040 <sqlite3_bind_int@plt>
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11f0 <sqlite_delete_address+0x70>
mov    %r14,%rdi
call   1060 <sqlite3_step@plt>
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
jne    1205 <sqlite_delete_address+0x85>
mov    %r15,%rdi
call   1080 <sqlite3_changes@plt>
test   %eax,%eax
jg     121f <sqlite_delete_address+0x9f>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
jmp    121f <sqlite_delete_address+0x9f>
mov    $0x2,%eax
jmp    1229 <sqlite_delete_address+0xa9>
lea    0xe3c(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <logprintf@plt>
jmp    121f <sqlite_delete_address+0x9f>
mov    %r15,%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe1b(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <logprintf@plt>
mov    %r14,%rdi
call   1090 <sqlite3_finalize@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [47 x i8] c"DELETE FROM addresses WHERE address_order = ?;\00"
@SQLITE_OK = global i64 0
@SQLITE_DONE = global i64 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [39 x i8] c"Failed to bind a statement parameter\0A\0A\00"
@.str.3 = [44 x i8] c"No such address, no modifications commited\0A\00"
define i32 @sqlite_delete_address(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i32* %0, i32** %4
store i64 %1, i64* %5
store i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %7
%9 = load i32*, i32** %4
%10 = load i8*, i8** %6
%11 = call i32* @database_prepare(i32* %9, i8* %10)
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 2, i32* %3
br label %45
15: ; preds = %2
%16 = load i32*, i32** %8
%17 = load i64, i64* %5
%18 = call i64 @sqlite3_bind_int(i32* %16, i32 1, i64 %17)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = load i32*, i32** %8
%23 = call i64 @sqlite3_step(i32* %22)
%24 = load i64, i64* @SQLITE_DONE
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32*, i32** %4
%28 = call i32 @sqlite3_errmsg(i32* %27)
%29 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 5, i32* %7
br label %30
30: ; preds = %26, %21
br label %33
31: ; preds = %15
%32 = call i32 (i32, i8*, ...) @logprintf(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
store i32 4, i32* %7
br label %33
33: ; preds = %31, %30
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = call i32 @sqlite3_changes(i32* %37)
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %36, %33
%43 = load i32*, i32** %8
%44 = call i32 @sqlite3_finalize(i32* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %14
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [47 x i8] c"DELETE FROM addresses WHERE address_order = ?;\00"
@SQLITE_OK = global i64 0
@SQLITE_DONE = global i64 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [39 x i8] c"Failed to bind a statement parameter\0A\0A\00"
@str = [43 x i8] c"No such address, no modifications commited\00"
define i32 @sqlite_delete_address(i32* %0, i64 %1) {
%3 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = tail call i64 @sqlite3_bind_int(i32* %3, i32 1, i64 %1)
%7 = load i64, i64* @SQLITE_OK
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = tail call i64 @sqlite3_step(i32* %3)
%11 = load i64, i64* @SQLITE_DONE
%12 = icmp eq i64 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = tail call i32 @sqlite3_errmsg(i32* %0)
%15 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %23
16: ; preds = %5
%17 = tail call i32 (i32, i8*, ...) @logprintf(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %23
18: ; preds = %9
%19 = tail call i32 @sqlite3_changes(i32* %0)
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %16, %13, %21, %18
%24 = tail call i32 @sqlite3_finalize(i32* %3)
br label %25
25: ; preds = %2, %23
%26 = phi i32 [ 0, %23 ], [ 2, %2 ]
ret i32 %26
}