#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 *, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
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_update_popd(sqlite3 *db, const char *user, int lock) {
  char *sql = "UPDATE popd SET pop_lock = ? WHERE pop_user = ?";
  sqlite3_stmt *stmt = database_prepare(db, sql);
  if (!stmt) {
    return 2;
  }
  if (sqlite3_bind_int(stmt, 1, lock) != SQLITE_OK) {
    logprintf(0, "Cannot bind popd lock.\n");
    return 81;
  }
  if (sqlite3_bind_text(stmt, 2, user, -1, SQLITE_STATIC) != SQLITE_OK) {
    logprintf(0, "Cannot bind user.\n");
    sqlite3_finalize(stmt);
    return 82;
  }
  if (sqlite3_step(stmt) != SQLITE_DONE) {
    logprintf(0, "%s\n", sqlite3_errmsg(db));
    sqlite3_finalize(stmt);
    return 5;
  }
  sqlite3_finalize(stmt);
  if (sqlite3_changes(db) < 1) {
    printf("POPD entry not found.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_update_popd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <database_prepare@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d6 <sqlite_update_popd+0x46>
movl   $0x2,-0x4(%rbp)
jmp    12e0 <sqlite_update_popd+0x150>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%rax
je     1213 <sqlite_update_popd+0x83>
xor    %edi,%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   10b0 <logprintf@plt>
movl   $0x51,-0x4(%rbp)
jmp    12e0 <sqlite_update_popd+0x150>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2db6(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1090 <sqlite3_bind_text@plt>
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%rax
je     1269 <sqlite_update_popd+0xd9>
xor    %edi,%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   10b0 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
movl   $0x52,-0x4(%rbp)
jmp    12e0 <sqlite_update_popd+0x150>
mov    -0x30(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2d57(%rip),%rcx
cmp    (%rcx),%rax
je     12b2 <sqlite_update_popd+0x122>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   10b0 <logprintf@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
movl   $0x5,-0x4(%rbp)
jmp    12e0 <sqlite_update_popd+0x150>
mov    -0x30(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_changes@plt>
cmp    $0x1,%eax
jge    12d9 <sqlite_update_popd+0x149>
lea    0xd8b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_update_popd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe5a(%rip),%rsi
call   1070 <database_prepare@plt>
test   %rax,%rax
je     122c <sqlite_update_popd+0x9c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1040 <sqlite3_bind_int@plt>
mov    0x2e1f(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1233 <sqlite_update_popd+0xa3>
mov    0x2e02(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1090 <sqlite3_bind_text@plt>
cmp    0x0(%rbp),%rax
jne    124a <sqlite_update_popd+0xba>
mov    %rbx,%rdi
call   1060 <sqlite3_step@plt>
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%rax
jne    1269 <sqlite_update_popd+0xd9>
mov    %rbx,%rdi
call   10a0 <sqlite3_finalize@plt>
mov    %r14,%rdi
call   1080 <sqlite3_changes@plt>
xor    %ebx,%ebx
test   %eax,%eax
jg     1290 <sqlite_update_popd+0x100>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
jmp    1290 <sqlite_update_popd+0x100>
mov    $0x2,%ebx
jmp    1290 <sqlite_update_popd+0x100>
lea    0xdf6(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   10b0 <logprintf@plt>
mov    $0x51,%ebx
jmp    1290 <sqlite_update_popd+0x100>
lea    0xdf7(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   10b0 <logprintf@plt>
mov    %rbx,%rdi
call   10a0 <sqlite3_finalize@plt>
mov    $0x52,%ebx
jmp    1290 <sqlite_update_popd+0x100>
mov    %r14,%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xde3(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <logprintf@plt>
mov    %rbx,%rdi
call   10a0 <sqlite3_finalize@plt>
mov    $0x5,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"UPDATE popd SET pop_lock = ? WHERE pop_user = ?\00"
@SQLITE_OK = global i64 0
@.str.1 = [24 x i8] c"Cannot bind popd lock.\0A\00"
@SQLITE_STATIC = global i32 0
@.str.2 = [19 x i8] c"Cannot bind user.\0A\00"
@SQLITE_DONE = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [23 x i8] c"POPD entry not found.\0A\00"
define i32 @sqlite_update_popd(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* getelementptr inbounds ([48 x i8], [48 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 %55
16: ; preds = %3
%17 = load i32*, i32** %9
%18 = load i32, i32* %7
%19 = call i64 @sqlite3_bind_int(i32* %17, i32 1, i32 %18)
%20 = load i64, i64* @SQLITE_OK
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 81, i32* %4
br label %55
24: ; preds = %16
%25 = load i32*, i32** %9
%26 = load i8*, i8** %6
%27 = load i32, i32* @SQLITE_STATIC
%28 = call i64 @sqlite3_bind_text(i32* %25, i32 2, i8* %26, i32 -1, i32 %27)
%29 = load i64, i64* @SQLITE_OK
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32*, i32** %9
%34 = call i32 @sqlite3_finalize(i32* %33)
store i32 82, i32* %4
br label %55
35: ; preds = %24
%36 = load i32*, i32** %9
%37 = call i64 @sqlite3_step(i32* %36)
%38 = load i64, i64* @SQLITE_DONE
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i32*, i32** %5
%42 = call i32 @sqlite3_errmsg(i32* %41)
%43 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = load i32*, i32** %9
%45 = call i32 @sqlite3_finalize(i32* %44)
store i32 5, i32* %4
br label %55
46: ; preds = %35
%47 = load i32*, i32** %9
%48 = call i32 @sqlite3_finalize(i32* %47)
%49 = load i32*, i32** %5
%50 = call i32 @sqlite3_changes(i32* %49)
%51 = icmp slt i32 %50, 1
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %46
store i32 0, i32* %4
br label %55
55: ; preds = %54, %40, %31, %22, %15
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
@.str = [48 x i8] c"UPDATE popd SET pop_lock = ? WHERE pop_user = ?\00"
@SQLITE_OK = global i64 0
@.str.1 = [24 x i8] c"Cannot bind popd lock.\0A\00"
@SQLITE_STATIC = global i32 0
@.str.2 = [19 x i8] c"Cannot bind user.\0A\00"
@SQLITE_DONE = global i64 0
@.str.3 = [4 x i8] c"%s\0A\00"
@str = [22 x i8] c"POPD entry not found.\00"
define i32 @sqlite_update_popd(i32* %0, i8* %1, i32 %2) {
%4 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %34, label %6
6: ; preds = %3
%7 = tail call i64 @sqlite3_bind_int(i32* %4, i32 1, i32 %2)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %34
12: ; preds = %6
%13 = load i32, i32* @SQLITE_STATIC
%14 = tail call i64 @sqlite3_bind_text(i32* %4, i32 2, i8* %1, i32 -1, i32 %13)
%15 = load i64, i64* @SQLITE_OK
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @sqlite3_finalize(i32* %4)
br label %34
20: ; preds = %12
%21 = tail call i64 @sqlite3_step(i32* %4)
%22 = load i64, i64* @SQLITE_DONE
%23 = icmp eq i64 %21, %22
br i1 %23, label %28, 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)
%27 = tail call i32 @sqlite3_finalize(i32* %4)
br label %34
28: ; preds = %20
%29 = tail call i32 @sqlite3_finalize(i32* %4)
%30 = tail call i32 @sqlite3_changes(i32* %0)
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %28, %32, %3, %24, %17, %10
%35 = phi i32 [ 81, %10 ], [ 82, %17 ], [ 5, %24 ], [ 2, %3 ], [ 0, %32 ], [ 0, %28 ]
ret i32 %35
}