#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*/ res;

/* Variables and functions */
char *sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stmt_get(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *settings_getString(char *name, char *defaultValue) {
  static char res[256];
  sqlite3_stmt *stmt = stmt_get(name);
  if (stmt == NULL)
    return defaultValue;
  const char *tmp = sqlite3_column_text(stmt, 0);
  if (strlen(tmp) >= sizeof(res)) {
    sqlite3_finalize(stmt);
    return defaultValue;
  }
  strcpy(res, tmp);
  sqlite3_finalize(stmt);
  return res;
}


x86 assembly (clang, -O0):
<settings_getString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <stmt_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1185 <settings_getString+0x35>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <settings_getString+0x95>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cltq
cmp    $0x100,%rax
jb     11c1 <settings_getString+0x71>
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e5 <settings_getString+0x95>
mov    -0x28(%rbp),%rsi
lea    0x2e94(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
lea    0x2e7f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<settings_getString>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1050 <stmt_get@plt>
test   %rax,%rax
je     119b <settings_getString+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0xff,%eax
ja     1193 <settings_getString+0x43>
lea    0x2ed8(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <sqlite3_finalize@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@settings_getString.res = internal global [256 x i8] zeroinitializer
define i8* @settings_getString(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32* @stmt_get(i8* %8)
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i8*, i8** %5
store i8* %13, i8** %3
br label %30
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = call i8* @sqlite3_column_text(i32* %15, i32 0)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = icmp uge i64 %19, 256
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = call i32 @sqlite3_finalize(i32* %22)
%24 = load i8*, i8** %5
store i8* %24, i8** %3
br label %30
25: ; preds = %14
%26 = load i8*, i8** %7
%27 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @settings_getString.res, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %6
%29 = call i32 @sqlite3_finalize(i32* %28)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @settings_getString.res, i64 0, i64 0), i8** %3
br label %30
30: ; preds = %25, %21, %12
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@settings_getString.res = internal global [256 x i8] zeroinitializer
define i8* @settings_getString(i8* %0, i8* readnone %1) {
%3 = tail call i32* @stmt_get(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i8* @sqlite3_column_text(i32* %3, i32 0)
%7 = tail call i32 @strlen(i8* %6)
%8 = icmp ugt i32 %7, 255
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @settings_getString.res, i64 0, i64 0), i8* %6)
br label %11
11: ; preds = %5, %9
%12 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @settings_getString.res, i64 0, i64 0), %9 ], [ %1, %5 ]
%13 = tail call i32 @sqlite3_finalize(i32* %3)
br label %14
14: ; preds = %11, %2
%15 = phi i8* [ %1, %2 ], [ %12, %11 ]
ret i8* %15
}