#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_add_popd(sqlite3 *db, const char *user) {
  char *sql = "INSERT INTO popd (pop_user) 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 user.\n");
    sqlite3_finalize(stmt);
    return 91;
  }
  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_add_popd>:
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   1050 <database_prepare@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <sqlite_add_popd+0x43>
movl   $0x2,-0x4(%rbp)
jmp    1252 <sqlite_add_popd+0xf2>
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     11f9 <sqlite_add_popd+0x99>
xor    %edi,%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x5b,-0x4(%rbp)
jmp    1252 <sqlite_add_popd+0xf2>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
je     1242 <sqlite_add_popd+0xe2>
mov    -0x10(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1080 <logprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
movl   $0x5,-0x4(%rbp)
jmp    1252 <sqlite_add_popd+0xf2>
mov    -0x28(%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_add_popd>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe8f(%rip),%rsi
call   1050 <database_prepare@plt>
test   %rax,%rax
je     11e0 <sqlite_add_popd+0x80>
mov    %rax,%rbx
mov    0x2e53(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    $0xffffffff,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
jne    11e7 <sqlite_add_popd+0x87>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e18(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
je     11fc <sqlite_add_popd+0x9c>
mov    %r14,%rdi
call   1030 <sqlite3_errmsg@plt>
lea    0xe6c(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x5,%ebp
jmp    11fc <sqlite_add_popd+0x9c>
mov    $0x2,%ebp
jmp    1204 <sqlite_add_popd+0xa4>
lea    0xe39(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1080 <logprintf@plt>
mov    $0x5b,%ebp
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"INSERT INTO popd (pop_user) VALUES (?)\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [19 x i8] c"Cannot bind user.\0A\00"
@SQLITE_DONE = global i64 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_add_popd(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 ([39 x i8], [39 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 %39
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 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %7
%24 = call i32 @sqlite3_finalize(i32* %23)
store i32 91, i32* %3
br label %39
25: ; preds = %14
%26 = load i32*, i32** %7
%27 = call i64 @sqlite3_step(i32* %26)
%28 = load i64, i64* @SQLITE_DONE
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i32*, i32** %4
%32 = call i32 @sqlite3_errmsg(i32* %31)
%33 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** %7
%35 = call i32 @sqlite3_finalize(i32* %34)
store i32 5, i32* %3
br label %39
36: ; preds = %25
%37 = load i32*, i32** %7
%38 = call i32 @sqlite3_finalize(i32* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %36, %30, %21, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [39 x i8] c"INSERT INTO popd (pop_user) VALUES (?)\00"
@SQLITE_STATIC = global i32 0
@SQLITE_OK = global i64 0
@.str.1 = [19 x i8] c"Cannot bind user.\0A\00"
@SQLITE_DONE = global i64 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @sqlite_add_popd(i32* %0, i8* %1) {
%3 = tail call i32* @database_prepare(i32* %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %22, 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 %12, label %10
10: ; preds = %5
%11 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %19
12: ; preds = %5
%13 = tail call i64 @sqlite3_step(i32* %3)
%14 = load i64, i64* @SQLITE_DONE
%15 = icmp eq i64 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = tail call i32 @sqlite3_errmsg(i32* %0)
%18 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %12, %10, %16
%20 = phi i32 [ 5, %16 ], [ 91, %10 ], [ 0, %12 ]
%21 = tail call i32 @sqlite3_finalize(i32* %3)
br label %22
22: ; preds = %19, %2
%23 = phi i32 [ 2, %2 ], [ %20, %19 ]
ret i32 %23
}