#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 /*<<< orphan*/ SQLITE_TRANSIENT;
int /*<<< orphan*/ finishedStmt(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *getConfigText(char *, int);
int /*<<< orphan*/ *getStmt(char *);
int runUpdate(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                                     int /*<<< orphan*/);
int setConfigTextValue(char *key, char *value) {
  char *currentValue = getConfigText(key, 1);
  sqlite3_stmt *stmt;
  if (currentValue == NULL) {
    stmt = getStmt("INSERT INTO config (key, value) VALUES (?, ?)");
    sqlite3_bind_text(stmt, 1, key, -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(stmt, 2, value, -1, SQLITE_TRANSIENT);
  } else {
    free(currentValue);
    stmt = getStmt("UPDATE config SET key=?, value=? WHERE key=?");
    sqlite3_bind_text(stmt, 1, key, -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(stmt, 2, value, -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
  }
  int status = runUpdate(stmt);
  finishedStmt(stmt);
  return status;
}


x86 assembly (clang, -O0):
<setConfigTextValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <getConfigText@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <setConfigTextValue+0x84>
lea    0xe6c(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2e34(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    0x2e13(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
jmp    1260 <setConfigTextValue+0x100>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe3a(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2dd4(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    0x2db3(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2d92(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
call   1050 <runUpdate@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <finishedStmt@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setConfigTextValue>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%esi
call   1040 <getConfigText@plt>
test   %rax,%rax
je     11dd <setConfigTextValue+0x7d>
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xea3(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,%rbx
mov    0x2e46(%rip),%rbp
mov    0x0(%rbp),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x0(%rbp),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x0(%rbp),%r8d
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
jmp    121b <setConfigTextValue+0xbb>
lea    0xe1c(%rip),%rdi
call   1060 <getStmt@plt>
mov    %rax,%rbx
mov    0x2ded(%rip),%rbp
mov    0x0(%rbp),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    0x0(%rbp),%r8d
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
call   1070 <sqlite3_bind_text@plt>
mov    %rbx,%rdi
call   1050 <runUpdate@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <finishedStmt@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"INSERT INTO config (key, value) VALUES (?, ?)\00"
@SQLITE_TRANSIENT = global i32 0
@.str.1 = [45 x i8] c"UPDATE config SET key=?, value=? WHERE key=?\00"
define i32 @setConfigTextValue(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i8* @getConfigText(i8* %8, i32 1)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = call i32* @getStmt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = load i8*, i8** %3
%16 = load i32, i32* @SQLITE_TRANSIENT
%17 = call i32 @sqlite3_bind_text(i32* %14, i32 1, i8* %15, i32 -1, i32 %16)
%18 = load i32*, i32** %6
%19 = load i8*, i8** %4
%20 = load i32, i32* @SQLITE_TRANSIENT
%21 = call i32 @sqlite3_bind_text(i32* %18, i32 2, i8* %19, i32 -1, i32 %20)
br label %38
22: ; preds = %2
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
%25 = call i32* @getStmt(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = load i8*, i8** %3
%28 = load i32, i32* @SQLITE_TRANSIENT
%29 = call i32 @sqlite3_bind_text(i32* %26, i32 1, i8* %27, i32 -1, i32 %28)
%30 = load i32*, i32** %6
%31 = load i8*, i8** %4
%32 = load i32, i32* @SQLITE_TRANSIENT
%33 = call i32 @sqlite3_bind_text(i32* %30, i32 2, i8* %31, i32 -1, i32 %32)
%34 = load i32*, i32** %6
%35 = load i8*, i8** %3
%36 = load i32, i32* @SQLITE_TRANSIENT
%37 = call i32 @sqlite3_bind_text(i32* %34, i32 3, i8* %35, i32 -1, i32 %36)
br label %38
38: ; preds = %22, %12
%39 = load i32*, i32** %6
%40 = call i32 @runUpdate(i32* %39)
store i32 %40, i32* %7
%41 = load i32*, i32** %6
%42 = call i32 @finishedStmt(i32* %41)
%43 = load i32, i32* %7
ret i32 %43
}

LLVM IR (-O2):
@.str = [46 x i8] c"INSERT INTO config (key, value) VALUES (?, ?)\00"
@SQLITE_TRANSIENT = global i32 0
@.str.1 = [45 x i8] c"UPDATE config SET key=?, value=? WHERE key=?\00"
define i32 @setConfigTextValue(i8* %0, i8* %1) {
%3 = tail call i8* @getConfigText(i8* %0, i32 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i32* @getStmt(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @SQLITE_TRANSIENT
%8 = tail call i32 @sqlite3_bind_text(i32* %6, i32 1, i8* %0, i32 -1, i32 %7)
%9 = load i32, i32* @SQLITE_TRANSIENT
%10 = tail call i32 @sqlite3_bind_text(i32* %6, i32 2, i8* %1, i32 -1, i32 %9)
br label %20
11: ; preds = %2
%12 = tail call i32 @free(i8* %3)
%13 = tail call i32* @getStmt(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @SQLITE_TRANSIENT
%15 = tail call i32 @sqlite3_bind_text(i32* %13, i32 1, i8* %0, i32 -1, i32 %14)
%16 = load i32, i32* @SQLITE_TRANSIENT
%17 = tail call i32 @sqlite3_bind_text(i32* %13, i32 2, i8* %1, i32 -1, i32 %16)
%18 = load i32, i32* @SQLITE_TRANSIENT
%19 = tail call i32 @sqlite3_bind_text(i32* %13, i32 3, i8* %0, i32 -1, i32 %18)
br label %20
20: ; preds = %11, %5
%21 = phi i32* [ %6, %5 ], [ %13, %11 ]
%22 = tail call i32 @runUpdate(i32* %21)
%23 = tail call i32 @finishedStmt(i32* %21)
ret i32 %22
}