#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_OK;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ *database_prepare(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ logprintf(int /*<<< orphan*/, 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_finalize(int /*<<< orphan*/ *);
int sqlite_delete_permissions(sqlite3 *db, const char *user) {
  char *sql = "DELETE FROM api_access WHERE api_user = ?";
  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 user.");
    sqlite3_finalize(stmt);
    return 101;
  }
  sqlite3_finalize(stmt);
  if (sqlite3_changes(db) < 1) {
    printf("No user entries found.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_delete_permissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <database_prepare@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <sqlite_delete_permissions+0x43>
movl   $0x2,-0x4(%rbp)
jmp    1225 <sqlite_delete_permissions+0xc5>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2e26(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
je     11f7 <sqlite_delete_permissions+0x97>
xor    %edi,%edi
lea    0xe4d(%rip),%rsi
call   1080 <logprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x65,-0x4(%rbp)
jmp    1225 <sqlite_delete_permissions+0xc5>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_changes@plt>
cmp    $0x1,%eax
jge    121e <sqlite_delete_permissions+0xbe>
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_delete_permissions>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe8e(%rip),%rsi
call   1040 <database_prepare@plt>
test   %rax,%rax
je     11ce <sqlite_delete_permissions+0x6e>
mov    %rax,%rbx
mov    0x2e52(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%rax
jne    11d5 <sqlite_delete_permissions+0x75>
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
mov    %r14,%rdi
call   1050 <sqlite3_changes@plt>
xor    %ebx,%ebx
test   %eax,%eax
jg     11f0 <sqlite_delete_permissions+0x90>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
jmp    11f0 <sqlite_delete_permissions+0x90>
mov    $0x2,%ebx
jmp    11f0 <sqlite_delete_permissions+0x90>
lea    0xe4e(%rip),%rsi
xor    %edi,%edi
call   1080 <logprintf@plt>
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
mov    $0x65,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [42 x i8] c"DELETE FROM api_access WHERE api_user = ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [18 x i8] c"Cannot bind user.\00"
@.str.2 = [24 x i8] c"No user entries found.\0A\00"
define i32 @sqlite_delete_permissions(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i32*, i32** %4
%9 = load i8*, i8** %6
%10 = call i32* @database_prepare(i32* %8, i8* %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 2, i32* %3
br label %34
14: ; preds = %2
%15 = load i32*, i32** %7
%16 = load i8*, i8** %5
%17 = load i32, i32* @SQLITE_STATIC
%18 = call i64 @sqlite3_bind_text(i32* %15, i32 1, i8* %16, i32 -1, i32 %17)
%19 = load i64, i64* @SQLITE_OK
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = call i32 @logprintf(i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %7
%24 = call i32 @sqlite3_finalize(i32* %23)
store i32 101, i32* %3
br label %34
25: ; preds = %14
%26 = load i32*, i32** %7
%27 = call i32 @sqlite3_finalize(i32* %26)
%28 = load i32*, i32** %4
%29 = call i32 @sqlite3_changes(i32* %28)
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
store i32 0, i32* %3
br label %34
34: ; preds = %33, %21, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [42 x i8] c"DELETE FROM api_access WHERE api_user = ?\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [18 x i8] c"Cannot bind user.\00"
@str = [23 x i8] c"No user entries found.\00"
define i32 @sqlite_delete_permissions(i32* %0, i8* %1) {
%3 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = load i32, i32* @SQLITE_STATIC
%7 = tail call i64 @sqlite3_bind_text(i32* %3, i32 1, i8* %1, i32 -1, i32 %6)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i32 @logprintf(i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @sqlite3_finalize(i32* %3)
br label %19
13: ; preds = %5
%14 = tail call i32 @sqlite3_finalize(i32* %3)
%15 = tail call i32 @sqlite3_changes(i32* %0)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %13, %17, %2, %10
%20 = phi i32 [ 101, %10 ], [ 2, %2 ], [ 0, %17 ], [ 0, %13 ]
ret i32 %20
}