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

/* Variables and functions */
scalar_t__ findKey(char const *, char const *, char const *, int *, int *,
                   unsigned long *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned long);
int getString(const char *buf, const char *section, const char *key,
              const char *defaultValue, char *value, unsigned long size) {
  int sectionStart, valueStart;
  unsigned long valueSize;
  if (findKey(buf, section, key, &sectionStart, &valueStart, &valueSize) != 0 ||
      valueSize == 0) {
    strncpy(value, defaultValue, size);
    return -1;
  }
  if (size - 1 < valueSize)
    valueSize = size - 1;
  memset(value, 0, size);
  strncpy(value, buf + valueStart, valueSize);
  return 0;
}


x86 assembly (clang, -O0):
<getString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x48(%rbp),%r9
call   1050 <findKey@plt>
cmp    $0x0,%rax
jne    1182 <getString+0x52>
cmpq   $0x0,-0x48(%rbp)
jne    119f <getString+0x6f>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <getString+0xbb>
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
cmp    -0x48(%rbp),%rax
jae    11bd <getString+0x8d>
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x40(%rbp),%rax
add    %rax,%rsi
mov    -0x48(%rbp),%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdi,%rbx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rsp,%r9
call   1050 <findKey@plt>
test   %rax,%rax
jne    119d <getString+0x6d>
mov    (%rsp),%rax
test   %rax,%rax
je     119d <getString+0x6d>
lea    -0x1(%r15),%rcx
cmp    %rax,%rcx
jae    1175 <getString+0x45>
mov    %rcx,(%rsp)
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
movslq 0x8(%rsp),%rax
add    %rax,%rbx
mov    (%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
jmp    11b0 <getString+0x80>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getString(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i64 %5, i64* %13
%17 = load i8*, i8** %8
%18 = load i8*, i8** %9
%19 = load i8*, i8** %10
%20 = call i64 @findKey(i8* %17, i8* %18, i8* %19, i32* %14, i32* %15, i64* %16)
%21 = icmp ne i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %6
%23 = load i64, i64* %16
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22, %6
%26 = load i8*, i8** %12
%27 = load i8*, i8** %11
%28 = load i64, i64* %13
%29 = call i32 @strncpy(i8* %26, i8* %27, i64 %28)
store i32 -1, i32* %7
br label %49
30: ; preds = %22
%31 = load i64, i64* %13
%32 = sub i64 %31, 1
%33 = load i64, i64* %16
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i64, i64* %13
%37 = sub i64 %36, 1
store i64 %37, i64* %16
br label %38
38: ; preds = %35, %30
%39 = load i8*, i8** %12
%40 = load i64, i64* %13
%41 = call i32 @memset(i8* %39, i32 0, i64 %40)
%42 = load i8*, i8** %12
%43 = load i8*, i8** %8
%44 = load i32, i32* %15
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i64, i64* %16
%48 = call i32 @strncpy(i8* %42, i8* %46, i64 %47)
store i32 0, i32* %7
br label %49
49: ; preds = %38, %25
%50 = load i32, i32* %7
ret i32 %50
}

LLVM IR (-O2):
define i32 @getString(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = bitcast i32* %7 to i8*
%11 = bitcast i32* %8 to i8*
%12 = bitcast i64* %9 to i8*
%13 = call i64 @findKey(i8* %0, i8* %1, i8* %2, i32* %7, i32* %8, i64* %9)
%14 = icmp ne i64 %13, 0
%15 = load i64, i64* %9
%16 = icmp eq i64 %15, 0
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %20
18: ; preds = %6
%19 = call i32 @strncpy(i8* %4, i8* %3, i64 %5)
br label %31
20: ; preds = %6
%21 = add i64 %5, -1
%22 = icmp ult i64 %21, %15
br i1 %22, label %23, label %24
23: ; preds = %20
store i64 %21, i64* %9
br label %24
24: ; preds = %23, %20
%25 = call i32 @memset(i8* %4, i32 0, i64 %5)
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i64, i64* %9
%30 = call i32 @strncpy(i8* %4, i8* %28, i64 %29)
br label %31
31: ; preds = %24, %18
%32 = phi i32 [ -1, %18 ], [ 0, %24 ]
ret i32 %32
}