#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, char *, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                             int /*<<< orphan*/);
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_user_delegation(sqlite3 *db, const char *user,
                                  const char *delegate) {
  char *sql =
      "DELETE FROM api_user_delegates WHERE api_user = ? AND api_delegate = ?";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_text(stmt, 1, user, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(1, "Cannot bind user.\n");
    sqlite3_finalize(stmt);
    return 3;
  }
  if (sqlite3_bind_text(stmt, 2, delegate, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(1, "Cannot bind delegate.\n");
    sqlite3_finalize(stmt);
    return 3;
  }
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    logprintf(0, "%s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    return 5;
  }
  if (sqlite3_changes(db) < 1) {
    printf("User not found or user doesn't have this delegate.\n");
  }
  sqlite3_finalize(stmt);
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_delete_user_delegation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe65(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <database_prepare@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c7 <sqlite_delete_user_delegation+0x47>
movl   $0x2,-0x4(%rbp)
jmp    12f0 <sqlite_delete_user_delegation+0x170>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e02(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <sqlite_delete_user_delegation+0xa0>
mov    $0x1,%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x3,-0x4(%rbp)
jmp    12f0 <sqlite_delete_user_delegation+0x170>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2da9(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%rax
je     1279 <sqlite_delete_user_delegation+0xf9>
mov    $0x1,%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x3,-0x4(%rbp)
jmp    12f0 <sqlite_delete_user_delegation+0x170>
mov    -0x30(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d47(%rip),%rcx
cmp    (%rcx),%rax
je     12c2 <sqlite_delete_user_delegation+0x142>
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   10a0 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
movl   $0x5,-0x4(%rbp)
jmp    12f0 <sqlite_delete_user_delegation+0x170>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_changes@plt>
cmp    $0x1,%eax
jge    12e0 <sqlite_delete_user_delegation+0x160>
lea    0xd9a(%rip),%rdi
call   1030 <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_user_delegation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe68(%rip),%rsi
call   1060 <database_prepare@plt>
test   %rax,%rax
je     1221 <sqlite_delete_user_delegation+0xa1>
mov    %rax,%rbx
mov    0x2e2c(%rip),%r12
mov    (%r12),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2e1c(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1228 <sqlite_delete_user_delegation+0xa8>
mov    (%r12),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    1231 <sqlite_delete_user_delegation+0xb1>
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rax
jne    125c <sqlite_delete_user_delegation+0xdc>
mov    %r14,%rdi
call   1070 <sqlite3_changes@plt>
xor    %ebp,%ebp
test   %eax,%eax
jg     1249 <sqlite_delete_user_delegation+0xc9>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
jmp    1249 <sqlite_delete_user_delegation+0xc9>
mov    $0x2,%ebp
jmp    1251 <sqlite_delete_user_delegation+0xd1>
lea    0xe18(%rip),%rsi
jmp    1238 <sqlite_delete_user_delegation+0xb8>
lea    0xe22(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <logprintf@plt>
mov    $0x3,%ebp
mov    %rbx,%rdi
call   1090 <sqlite3_finalize@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe06(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <logprintf@plt>
mov    $0x5,%ebp
jmp    1249 <sqlite_delete_user_delegation+0xc9>

LLVM IR (-O0):
@.str = [71 x i8] c"DELETE FROM api_user_delegates WHERE api_user = ? AND api_delegate = ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [19 x i8] c"Cannot bind user.\0A\00"
@.str.2 = [23 x i8] c"Cannot bind delegate.\0A\00"
@SQLITE_DONE = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [52 x i8] c"User not found or user doesn't have this delegate.\0A\00"
define i32 @sqlite_delete_user_delegation(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 ([71 x i8], [71 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 %58
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 1, i8* getelementptr inbounds ([19 x i8], [19 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 %58
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 1, i8* getelementptr inbounds ([23 x i8], [23 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 %58
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 %58
49: ; preds = %38
%50 = load i32*, i32** %5
%51 = call i32 @sqlite3_changes(i32* %50)
%52 = icmp slt i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = load i32*, i32** %9
%57 = call i32 @sqlite3_finalize(i32* %56)
store i32 0, i32* %4
br label %58
58: ; preds = %55, %43, %34, %23, %15
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str = [71 x i8] c"DELETE FROM api_user_delegates WHERE api_user = ? AND api_delegate = ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [19 x i8] c"Cannot bind user.\0A\00"
@.str.2 = [23 x i8] c"Cannot bind delegate.\0A\00"
@SQLITE_DONE = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
@str = [51 x i8] c"User not found or user doesn't have this delegate.\00"
define i32 @sqlite_delete_user_delegation(i32* %0, i8* %1, i8* %2) {
%4 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %35, 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 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %32
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 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %32
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 %32
27: ; preds = %20
%28 = tail call i32 @sqlite3_changes(i32* %0)
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %27, %30, %11, %18, %24
%33 = phi i32 [ 5, %24 ], [ 3, %18 ], [ 3, %11 ], [ 0, %30 ], [ 0, %27 ]
%34 = tail call i32 @sqlite3_finalize(i32* %4)
br label %35
35: ; preds = %32, %3
%36 = phi i32 [ 2, %3 ], [ %33, %32 ]
ret i32 %36
}