#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__ readLine(char *);
int /*<<< orphan*/ rewindBuffer();
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
int iniFileGetString(char *section, char *entry, char *defVal, char *buffer,
                     int bufferLen) {
  char def[512];
  char buff[512];
  char *ep;
  char t_section[512];
  int len = strlen(entry);
  rewindBuffer();
  strcpy(def, defVal);
  sprintf(t_section, "[%s]", section);
  do {
    if (readLine(buff) < 0) {
      strncpy(buffer, def, bufferLen);
      buffer[bufferLen - 1] = '\0';
      return strlen(buffer);
    }
  } while (strcmp(buff, t_section));
  do {
    if (readLine(buff) < 0 || buff[0] == '[') {
      strncpy(buffer, def, bufferLen);
      buffer[bufferLen - 1] = '\0';
      return strlen(buffer);
    }
  } while (strncmp(buff, entry, len));
  ep = strrchr(buff, '=');
  ep++;
  strncpy(buffer, ep, bufferLen);
  buffer[bufferLen - 1] = '\0';
  return strlen(buffer);
}


x86 assembly (clang, -O0):
<iniFileGetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x644(%rbp)
mov    $0x0,%al
call   1060 <rewindBuffer@plt>
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x640(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   10a0 <readLine@plt>
cmp    $0x0,%rax
jge    1237 <iniFileGetString+0xa7>
mov    -0x28(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1338 <iniFileGetString+0x1a8>
jmp    123c <iniFileGetString+0xac>
lea    -0x430(%rbp),%rdi
lea    -0x640(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <iniFileGetString+0x5c>
jmp    125e <iniFileGetString+0xce>
lea    -0x430(%rbp),%rdi
call   10a0 <readLine@plt>
cmp    $0x0,%rax
jl     1284 <iniFileGetString+0xf4>
movsbl -0x430(%rbp),%eax
cmp    $0x5b,%eax
jne    12b9 <iniFileGetString+0x129>
mov    -0x28(%rbp),%rdi
lea    -0x230(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1338 <iniFileGetString+0x1a8>
jmp    12be <iniFileGetString+0x12e>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x644(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    125e <iniFileGetString+0xce>
lea    -0x430(%rbp),%rdi
mov    $0x3d,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniFileGetString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %r8d,0xc(%rsp)
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1070 <strlen@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1060 <rewindBuffer@plt>
lea    0x410(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
call   1050 <strcpy@plt>
lea    0xe22(%rip),%rsi
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10a0 <readLine@plt>
test   %rax,%rax
js     126d <iniFileGetString+0xdd>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1200 <iniFileGetString+0x70>
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   10a0 <readLine@plt>
test   %rax,%rax
js     126d <iniFileGetString+0xdd>
cmpb   $0x5b,0x10(%rsp)
je     126d <iniFileGetString+0xdd>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1230 <iniFileGetString+0xa0>
lea    0x10(%rsp),%rdi
mov    $0x3d,%esi
call   1080 <strrchr@plt>
mov    %rax,%r12
add    $0x1,%r12
mov    0xc(%rsp),%ebx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r15,%rdi
call   1070 <strlen@plt>
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"[%s]\00"
define i32 @iniFileGetString(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [512 x i8]
%13 = alloca [512 x i8]
%14 = alloca i8*
%15 = alloca [512 x i8]
%16 = alloca i32
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
%17 = load i8*, i8** %8
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %16
%19 = call i32 (...) @rewindBuffer()
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%21 = load i8*, i8** %9
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%24 = load i8*, i8** %7
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %43, %5
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%28 = call i64 @readLine(i8* %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %26
%31 = load i8*, i8** %10
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%33 = load i32, i32* %11
%34 = call i32 @strncpy(i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %10
%36 = load i32, i32* %11
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %10
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %6
br label %93
42: ; preds = %26
br label %43
43: ; preds = %42
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%46 = call i64 @strcmp(i8* %44, i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %26, label %48
48: ; preds = %43
br label %49
49: ; preds = %71, %48
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%51 = call i64 @readLine(i8* %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %49
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 91
br i1 %57, label %58, label %70
58: ; preds = %53, %49
%59 = load i8*, i8** %10
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%61 = load i32, i32* %11
%62 = call i32 @strncpy(i8* %59, i8* %60, i32 %61)
%63 = load i8*, i8** %10
%64 = load i32, i32* %11
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 0, i8* %67
%68 = load i8*, i8** %10
%69 = call i32 @strlen(i8* %68)
store i32 %69, i32* %6
br label %93
70: ; preds = %53
br label %71
71: ; preds = %70
%72 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%73 = load i8*, i8** %8
%74 = load i32, i32* %16
%75 = call i64 @strncmp(i8* %72, i8* %73, i32 %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %49, label %77
77: ; preds = %71
%78 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%79 = call i8* @strrchr(i8* %78, i8 signext 61)
store i8* %79, i8** %14
%80 = load i8*, i8** %14
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %14
%82 = load i8*, i8** %10
%83 = load i8*, i8** %14
%84 = load i32, i32* %11
%85 = call i32 @strncpy(i8* %82, i8* %83, i32 %84)
%86 = load i8*, i8** %10
%87 = load i32, i32* %11
%88 = sub nsw i32 %87, 1
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %86, i64 %89
store i8 0, i8* %90
%91 = load i8*, i8** %10
%92 = call i32 @strlen(i8* %91)
store i32 %92, i32* %6
br label %93
93: ; preds = %77, %58, %30
%94 = load i32, i32* %6
ret i32 %94
}

LLVM IR (-O2):
@.str = [5 x i8] c"[%s]\00"
define i32 @iniFileGetString(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%12 = tail call i32 @strlen(i8* %1)
%13 = tail call i32 (...) @rewindBuffer()
%14 = call i32 @strcpy(i8* %9, i8* %2)
%15 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %19, %5
%17 = call i64 @readLine(i8* %10)
%18 = icmp slt i64 %17, 0
br i1 %18, label %34, label %19
19: ; preds = %16
%20 = call i64 @strcmp(i8* %10, i8* %11)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %16
22: ; preds = %19, %28
%23 = call i64 @readLine(i8* %10)
%24 = icmp slt i64 %23, 0
%25 = load i8, i8* %10
%26 = icmp eq i8 %25, 91
%27 = select i1 %24, i1 true, i1 %26
br i1 %27, label %34, label %28
28: ; preds = %22
%29 = call i64 @strncmp(i8* %10, i8* %1, i32 %12)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %22
31: ; preds = %28
%32 = call i8* @strrchr(i8* %10, i8 signext 61)
%33 = getelementptr inbounds i8, i8* %32, i64 1
br label %34
34: ; preds = %16, %22, %31
%35 = phi i8* [ %33, %31 ], [ %9, %22 ], [ %9, %16 ]
%36 = call i32 @strncpy(i8* %3, i8* %35, i32 %4)
%37 = add nsw i32 %4, -1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %3, i64 %38
store i8 0, i8* %39
%40 = call i32 @strlen(i8* %3)
ret i32 %40
}