#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;

/* Variables and functions */
int SQLITE_ERROR;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ *sql_prepare(char *);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *,
                                     int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int add_quote(const char *quote, const char *user) {
  int status;
  sqlite3_stmt *stmt;
  stmt = sql_prepare("INSERT INTO quotes(quote, user_id) VALUES(?1, (SELECT "
                     "user_id FROM users WHERE name = ?2))");
  if (!stmt)
    return SQLITE_ERROR;
  sqlite3_bind_text(stmt, 1, quote, strlen(quote), SQLITE_STATIC);
  sqlite3_bind_text(stmt, 2, user, strlen(user), SQLITE_STATIC);
  status = sqlite3_step(stmt);
  sqlite3_finalize(stmt);
  return status;
}


x86 assembly (clang, -O0):
<add_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe99(%rip),%rdi
call   1050 <sql_prepare@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118c <add_quote+0x3c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1215 <add_quote+0xc5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
mov    0x2e22(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
call   1060 <sqlite3_bind_text@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    0x2deb(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
call   1060 <sqlite3_bind_text@plt>
mov    -0x28(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_quote>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9c(%rip),%rdi
call   1050 <sql_prepare@plt>
test   %rax,%rax
je     11ca <add_quote+0x7a>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    0x2e58(%rip),%rbp
mov    0x0(%rbp),%r8d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    0x0(%rbp),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1060 <sqlite3_bind_text@plt>
mov    %rbx,%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
mov    %ebp,%eax
jmp    11d3 <add_quote+0x83>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [91 x i8] c"INSERT INTO quotes(quote, user_id) VALUES(?1, (SELECT user_id FROM users WHERE name = ?2))\00"
@SQLITE_ERROR = global i32 0
@SQLITE_STATIC = global i32 0
define i32 @add_quote(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call i32* @sql_prepare(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = load i32, i32* @SQLITE_ERROR
store i32 %12, i32* %3
br label %31
13: ; preds = %2
%14 = load i32*, i32** %7
%15 = load i8*, i8** %4
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = load i32, i32* @SQLITE_STATIC
%19 = call i32 @sqlite3_bind_text(i32* %14, i32 1, i8* %15, i32 %17, i32 %18)
%20 = load i32*, i32** %7
%21 = load i8*, i8** %5
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = load i32, i32* @SQLITE_STATIC
%25 = call i32 @sqlite3_bind_text(i32* %20, i32 2, i8* %21, i32 %23, i32 %24)
%26 = load i32*, i32** %7
%27 = call i32 @sqlite3_step(i32* %26)
store i32 %27, i32* %6
%28 = load i32*, i32** %7
%29 = call i32 @sqlite3_finalize(i32* %28)
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %31
31: ; preds = %13, %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [91 x i8] c"INSERT INTO quotes(quote, user_id) VALUES(?1, (SELECT user_id FROM users WHERE name = ?2))\00"
@SQLITE_ERROR = global i32 0
@SQLITE_STATIC = global i32 0
define i32 @add_quote(i8* %0, i8* %1) {
%3 = tail call i32* @sql_prepare(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load i32, i32* @SQLITE_ERROR
br label %16
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %0)
%9 = load i32, i32* @SQLITE_STATIC
%10 = tail call i32 @sqlite3_bind_text(i32* %3, i32 1, i8* %0, i32 %8, i32 %9)
%11 = tail call i32 @strlen(i8* %1)
%12 = load i32, i32* @SQLITE_STATIC
%13 = tail call i32 @sqlite3_bind_text(i32* %3, i32 2, i8* %1, i32 %11, i32 %12)
%14 = tail call i32 @sqlite3_step(i32* %3)
%15 = tail call i32 @sqlite3_finalize(i32* %3)
br label %16
16: ; preds = %7, %5
%17 = phi i32 [ %14, %7 ], [ %6, %5 ]
ret i32 %17
}