#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_delegate_address(sqlite3 *db, const char *user,
                            const char *expression) {
  char *sql = "INSERT INTO api_address_delegates (api_user, api_expression) "
              "VALUES (?, ?)";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, user, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Cannot bind username.\n");
    sqlite3_finalize(stmt);
    return 3;
  }
  if (sqlite3_bind_text(stmt, 2, expression, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Cannot bind expression.\n");
    sqlite3_finalize(stmt);
    return 3;
  }
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    logprintf(0, "%s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    return 5;
  }
  sqlite3_finalize(stmt);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_delegate_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe85(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <database_prepare@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a7 <sqlite_delegate_address+0x47>
movl   $0x2,-0x4(%rbp)
jmp    12ac <sqlite_delegate_address+0x14c>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e22(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11fd <sqlite_delegate_address+0x9d>
xor    %edi,%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x3,-0x4(%rbp)
jmp    12ac <sqlite_delegate_address+0x14c>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2dcc(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
je     1253 <sqlite_delegate_address+0xf3>
xor    %edi,%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x3,-0x4(%rbp)
jmp    12ac <sqlite_delegate_address+0x14c>
mov    -0x30(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2d6d(%rip),%rcx
cmp    (%rcx),%rax
je     129c <sqlite_delegate_address+0x13c>
mov    -0x10(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x5,-0x4(%rbp)
jmp    12ac <sqlite_delegate_address+0x14c>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_delegate_address>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe88(%rip),%rsi
call   1050 <database_prepare@plt>
test   %rax,%rax
je     120c <sqlite_delegate_address+0xac>
mov    %rax,%rbx
mov    0x2e48(%rip),%r12
mov    (%r12),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e38(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1213 <sqlite_delegate_address+0xb3>
mov    (%r12),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    121c <sqlite_delegate_address+0xbc>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
mov    0x2dec(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     1231 <sqlite_delegate_address+0xd1>
mov    %r14,%rdi
call   1030 <sqlite3_errmsg@plt>
lea    0xe81(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x5,%ebp
jmp    1231 <sqlite_delegate_address+0xd1>
mov    $0x2,%ebp
jmp    1239 <sqlite_delegate_address+0xd9>
lea    0xe31(%rip),%rsi
jmp    1223 <sqlite_delegate_address+0xc3>
lea    0xe3f(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x3,%ebp
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"INSERT INTO api_address_delegates (api_user, api_expression) VALUES (?, ?)\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [23 x i8] c"Cannot bind username.\0A\00"
@.str.2 = [25 x i8] c"Cannot bind expression.\0A\00"
@SQLITE_DONE = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_delegate_address(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i32*, i32** %5
%11 = load i8*, i8** %8
%12 = call i32* @database_prepare(i32* %10, i8* %11)
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %3
store i32 2, i32* %4
br label %52
16: ; preds = %3
%17 = load i32*, i32** %9
%18 = load i8*, i8** %6
%19 = load i32, i32* @SQLITE_STATIC
%20 = call i64 @sqlite3_bind_text(i32* %17, i32 1, i8* %18, i32 -1, i32 %19)
%21 = load i64, i64* @SQLITE_OK
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32*, i32** %9
%26 = call i32 @sqlite3_finalize(i32* %25)
store i32 3, i32* %4
br label %52
27: ; preds = %16
%28 = load i32*, i32** %9
%29 = load i8*, i8** %7
%30 = load i32, i32* @SQLITE_STATIC
%31 = call i64 @sqlite3_bind_text(i32* %28, i32 2, i8* %29, i32 -1, i32 %30)
%32 = load i64, i64* @SQLITE_OK
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32*, i32** %9
%37 = call i32 @sqlite3_finalize(i32* %36)
store i32 3, i32* %4
br label %52
38: ; preds = %27
%39 = load i32*, i32** %9
%40 = call i64 @sqlite3_step(i32* %39)
%41 = load i64, i64* @SQLITE_DONE
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32*, i32** %5
%45 = call i32 @sqlite3_errmsg(i32* %44)
%46 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %9
%48 = call i32 @sqlite3_finalize(i32* %47)
store i32 5, i32* %4
br label %52
49: ; preds = %38
%50 = load i32*, i32** %9
%51 = call i32 @sqlite3_finalize(i32* %50)
store i32 0, i32* %4
br label %52
52: ; preds = %49, %43, %34, %23, %15
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [75 x i8] c"INSERT INTO api_address_delegates (api_user, api_expression) VALUES (?, ?)\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [23 x i8] c"Cannot bind username.\0A\00"
@.str.2 = [25 x i8] c"Cannot bind expression.\0A\00"
@SQLITE_DONE = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_delegate_address(i32* %0, i8* %1, i8* %2) {
%4 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %30, label %6
6: ; preds = %3
%7 = load i32, i32* @SQLITE_STATIC
%8 = tail call i64 @sqlite3_bind_text(i32* %4, i32 1, i8* %1, i32 -1, i32 %7)
%9 = load i64, i64* @SQLITE_OK
%10 = icmp eq i64 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %27
13: ; preds = %6
%14 = load i32, i32* @SQLITE_STATIC
%15 = tail call i64 @sqlite3_bind_text(i32* %4, i32 2, i8* %2, i32 -1, i32 %14)
%16 = load i64, i64* @SQLITE_OK
%17 = icmp eq i64 %15, %16
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %27
20: ; preds = %13
%21 = tail call i64 @sqlite3_step(i32* %4)
%22 = load i64, i64* @SQLITE_DONE
%23 = icmp eq i64 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call i32 @sqlite3_errmsg(i32* %0)
%26 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %20, %11, %18, %24
%28 = phi i32 [ 5, %24 ], [ 3, %18 ], [ 3, %11 ], [ 0, %20 ]
%29 = tail call i32 @sqlite3_finalize(i32* %4)
br label %30
30: ; preds = %27, %3
%31 = phi i32 [ 2, %3 ], [ %28, %27 ]
ret i32 %31
}