#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 */
char *SearchKey(char *, char const *);
char *SearchSection(char *, char const *);
char *file2buf(char const *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int const);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int const);
void GetPrivateProfileString(const char *section, const char *var,
                             const char *def, char *get, const int length,
                             const char *filename) {
  char *buf;
  char *section_found;
  char *key_found;
  memset(get, 0, length);
  if (!filename) {
    strncpy(get, def, length);
    return;
  }
  buf = file2buf(filename);
  if (buf) {
    section_found = SearchSection(buf, section);
    if (section_found) {
      key_found = SearchKey(section_found, var);
      if (key_found) {
        char *val_start;
        char *val_end;
        val_start = strchr(key_found, '=') + 1;
        val_end = val_start;
        while ((*val_end != '\0') && (*val_end != '\n') && (*val_end != '\r'))
          val_end++;
        strncpy(get, val_start, val_end - val_start);
        get[val_end - val_start] = '\0';
        return;
      }
    }
  }
  strncpy(get, def, length);
}


x86 assembly (clang, -O0):
<GetPrivateProfileString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmpq   $0x0,-0x30(%rbp)
jne    11ae <GetPrivateProfileString+0x4e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
jmp    12c3 <GetPrivateProfileString+0x163>
mov    -0x30(%rbp),%rdi
call   1070 <file2buf@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12b3 <GetPrivateProfileString+0x153>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <SearchSection@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12ae <GetPrivateProfileString+0x14e>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <SearchKey@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12a9 <GetPrivateProfileString+0x149>
mov    -0x48(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x59(%rbp)
je     1256 <GetPrivateProfileString+0xf6>
mov    -0x58(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x59(%rbp)
je     1256 <GetPrivateProfileString+0xf6>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    1266 <GetPrivateProfileString+0x106>
jmp    1277 <GetPrivateProfileString+0x117>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    121c <GetPrivateProfileString+0xbc>
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12c3 <GetPrivateProfileString+0x163>
jmp    12ae <GetPrivateProfileString+0x14e>
jmp    12b3 <GetPrivateProfileString+0x153>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPrivateProfileString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8d,%ebp
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rcx,%rdi
xor    %esi,%esi
mov    %r8d,%edx
call   1050 <memset@plt>
test   %rbx,%rbx
je     1216 <GetPrivateProfileString+0xb6>
mov    %rbx,%rdi
call   1070 <file2buf@plt>
test   %rax,%rax
je     1216 <GetPrivateProfileString+0xb6>
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <SearchSection@plt>
test   %rax,%rax
je     1216 <GetPrivateProfileString+0xb6>
mov    %rax,%rdi
mov    %r15,%rsi
call   1080 <SearchKey@plt>
test   %rax,%rax
je     1216 <GetPrivateProfileString+0xb6>
mov    %rax,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
add    $0x1,%rax
xor    %ebp,%ebp
mov    $0x2401,%ecx
jmp    11e4 <GetPrivateProfileString+0x84>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
movzbl (%rax,%rbp,1),%edx
cmp    $0xd,%rdx
ja     11e0 <GetPrivateProfileString+0x80>
bt     %rdx,%rcx
jae    11e0 <GetPrivateProfileString+0x80>
mov    %r13,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%r13,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
define void @GetPrivateProfileString(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%18 = load i8*, i8** %10
%19 = load i32, i32* %11
%20 = call i32 @memset(i8* %18, i32 0, i32 %19)
%21 = load i8*, i8** %12
%22 = icmp ne i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %6
%24 = load i8*, i8** %10
%25 = load i8*, i8** %9
%26 = load i32, i32* %11
%27 = call i32 @strncpy(i8* %24, i8* %25, i32 %26)
br label %94
28: ; preds = %6
%29 = load i8*, i8** %12
%30 = call i8* @file2buf(i8* %29)
store i8* %30, i8** %13
%31 = load i8*, i8** %13
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %89
33: ; preds = %28
%34 = load i8*, i8** %13
%35 = load i8*, i8** %7
%36 = call i8* @SearchSection(i8* %34, i8* %35)
store i8* %36, i8** %14
%37 = load i8*, i8** %14
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %88
39: ; preds = %33
%40 = load i8*, i8** %14
%41 = load i8*, i8** %8
%42 = call i8* @SearchKey(i8* %40, i8* %41)
store i8* %42, i8** %15
%43 = load i8*, i8** %15
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %87
45: ; preds = %39
%46 = load i8*, i8** %15
%47 = call i8* @strchr(i8* %46, i8 signext 61)
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %16
%49 = load i8*, i8** %16
store i8* %49, i8** %17
br label %50
50: ; preds = %67, %45
%51 = load i8*, i8** %17
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %50
%56 = load i8*, i8** %17
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 10
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = load i8*, i8** %17
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 13
br label %65
65: ; preds = %60, %55, %50
%66 = phi i1 [ false, %55 ], [ false, %50 ], [ %64, %60 ]
br i1 %66, label %67, label %70
67: ; preds = %65
%68 = load i8*, i8** %17
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %17
br label %50
70: ; preds = %65
%71 = load i8*, i8** %10
%72 = load i8*, i8** %16
%73 = load i8*, i8** %17
%74 = load i8*, i8** %16
%75 = ptrtoint i8* %73 to i64
%76 = ptrtoint i8* %74 to i64
%77 = sub i64 %75, %76
%78 = trunc i64 %77 to i32
%79 = call i32 @strncpy(i8* %71, i8* %72, i32 %78)
%80 = load i8*, i8** %10
%81 = load i8*, i8** %17
%82 = load i8*, i8** %16
%83 = ptrtoint i8* %81 to i64
%84 = ptrtoint i8* %82 to i64
%85 = sub i64 %83, %84
%86 = getelementptr inbounds i8, i8* %80, i64 %85
store i8 0, i8* %86
br label %94
87: ; preds = %39
br label %88
88: ; preds = %87, %33
br label %89
89: ; preds = %88, %28
%90 = load i8*, i8** %10
%91 = load i8*, i8** %9
%92 = load i32, i32* %11
%93 = call i32 @strncpy(i8* %90, i8* %91, i32 %92)
br label %94
94: ; preds = %89, %70, %23
ret void
}

LLVM IR (-O2):
define void @GetPrivateProfileString(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5) {
%7 = tail call i32 @memset(i8* %3, i32 0, i32 %4)
%8 = icmp eq i8* %5, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @strncpy(i8* %3, i8* %2, i32 %4)
br label %37
11: ; preds = %6
%12 = tail call i8* @file2buf(i8* %5)
%13 = icmp eq i8* %12, null
br i1 %13, label %35, label %14
14: ; preds = %11
%15 = tail call i8* @SearchSection(i8* %12, i8* %0)
%16 = icmp eq i8* %15, null
br i1 %16, label %35, label %17
17: ; preds = %14
%18 = tail call i8* @SearchKey(i8* %15, i8* %1)
%19 = icmp eq i8* %18, null
br i1 %19, label %35, label %20
20: ; preds = %17
%21 = tail call i8* @strchr(i8* %18, i8 signext 61)
%22 = getelementptr inbounds i8, i8* %21, i64 1
br label %23
23: ; preds = %26, %20
%24 = phi i8* [ %22, %20 ], [ %27, %26 ]
%25 = load i8, i8* %24
switch i8 %25, label %26 [
i8 0, label %28
i8 10, label %28
i8 13, label %28
]
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %24, i64 1
br label %23
28: ; preds = %23, %23, %23
%29 = ptrtoint i8* %24 to i64
%30 = ptrtoint i8* %22 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = tail call i32 @strncpy(i8* %3, i8* %22, i32 %32)
%34 = getelementptr inbounds i8, i8* %3, i64 %31
store i8 0, i8* %34
br label %37
35: ; preds = %14, %17, %11
%36 = tail call i32 @strncpy(i8* %3, i8* %2, i32 %4)
br label %37
37: ; preds = %35, %28, %9
ret void
}