#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_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                                     int /*<<< orphan*/);
int setConfigIntValue(char *key, int 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_int(stmt, 2, value);
  } else {
    free(currentValue);
    stmt = getStmt("UPDATE config SET key=?, value=? WHERE key=?");
    sqlite3_bind_text(stmt, 1, key, -1, SQLITE_TRANSIENT);
    sqlite3_bind_int(stmt, 2, value);
    sqlite3_bind_text(stmt, 3, key, -1, SQLITE_TRANSIENT);
  }
  int status = runUpdate(stmt);
  finishedStmt(stmt);
  return status;
}


x86 assembly (clang, -O0):
<setConfigIntValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <getConfigText@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <setConfigIntValue+0x73>
lea    0xe5d(%rip),%rdi
call   1070 <getStmt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2e25(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x2,%esi
call   1060 <sqlite3_bind_int@plt>
jmp    124f <setConfigIntValue+0xdf>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe3b(%rip),%rdi
call   1070 <getStmt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2dd5(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x2,%esi
call   1060 <sqlite3_bind_int@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x2da3(%rip),%rax
mov    (%rax),%r8d
mov    $0x3,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    -0x20(%rbp),%rdi
call   1050 <runUpdate@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <finishedStmt@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setConfigIntValue>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
mov    $0x1,%esi
call   1040 <getConfigText@plt>
test   %rax,%rax
je     11ec <setConfigIntValue+0x7c>
mov    %rax,%rdi
call   1030 <free@plt>
lea    0xe93(%rip),%rdi
call   1070 <getStmt@plt>
mov    %rax,%rbp
mov    0x2e36(%rip),%r15
mov    (%r15),%r8d
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    %rbp,%rdi
mov    $0x2,%esi
mov    %r14d,%edx
call   1060 <sqlite3_bind_int@plt>
mov    (%r15),%r8d
mov    %rbp,%rdi
mov    $0x3,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
jmp    122a <setConfigIntValue+0xba>
lea    0xe0d(%rip),%rdi
call   1070 <getStmt@plt>
mov    %rax,%rbp
mov    0x2dde(%rip),%rax
mov    (%rax),%r8d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    %rbp,%rdi
mov    $0x2,%esi
mov    %r14d,%edx
call   1060 <sqlite3_bind_int@plt>
mov    %rbp,%rdi
call   1050 <runUpdate@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1090 <finishedStmt@plt>
mov    %ebx,%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 @setConfigIntValue(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %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 %21
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 i32, i32* %4
%20 = call i32 @sqlite3_bind_int(i32* %18, i32 2, i32 %19)
br label %36
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = call i32 @free(i8* %22)
%24 = call i32* @getStmt(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = load i8*, i8** %3
%27 = load i32, i32* @SQLITE_TRANSIENT
%28 = call i32 @sqlite3_bind_text(i32* %25, i32 1, i8* %26, i32 -1, i32 %27)
%29 = load i32*, i32** %6
%30 = load i32, i32* %4
%31 = call i32 @sqlite3_bind_int(i32* %29, i32 2, i32 %30)
%32 = load i32*, i32** %6
%33 = load i8*, i8** %3
%34 = load i32, i32* @SQLITE_TRANSIENT
%35 = call i32 @sqlite3_bind_text(i32* %32, i32 3, i8* %33, i32 -1, i32 %34)
br label %36
36: ; preds = %21, %12
%37 = load i32*, i32** %6
%38 = call i32 @runUpdate(i32* %37)
store i32 %38, i32* %7
%39 = load i32*, i32** %6
%40 = call i32 @finishedStmt(i32* %39)
%41 = load i32, i32* %7
ret i32 %41
}

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 @setConfigIntValue(i8* %0, i32 %1) {
%3 = tail call i8* @getConfigText(i8* %0, i32 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %10
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 = tail call i32 @sqlite3_bind_int(i32* %6, i32 2, i32 %1)
br label %18
10: ; preds = %2
%11 = tail call i32 @free(i8* %3)
%12 = tail call i32* @getStmt(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @SQLITE_TRANSIENT
%14 = tail call i32 @sqlite3_bind_text(i32* %12, i32 1, i8* %0, i32 -1, i32 %13)
%15 = tail call i32 @sqlite3_bind_int(i32* %12, i32 2, i32 %1)
%16 = load i32, i32* @SQLITE_TRANSIENT
%17 = tail call i32 @sqlite3_bind_text(i32* %12, i32 3, i8* %0, i32 -1, i32 %16)
br label %18
18: ; preds = %10, %5
%19 = phi i32* [ %6, %5 ], [ %12, %10 ]
%20 = tail call i32 @runUpdate(i32* %19)
%21 = tail call i32 @finishedStmt(i32* %19)
ret i32 %20
}