#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 */
int readLine(char *);
int /*<<< orphan*/ rewindBuffer();
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int iniFileGetSection(char *section, char *buffer, int bufferLen) {
  char buff[512];
  char t_section[512];
  int offset = 0;
  int len;
  rewindBuffer();
  sprintf(t_section, "[%s]", section);
  do {
    if (readLine(buff) < 0) {
      buffer[offset++] = '\0';
      buffer[offset++] = '\0';
      return strlen(buffer);
    }
  } while (strcmp(buff, t_section));
  while ((len = readLine(buff)) >= 0 && buff[0] != '[') {
    if (offset + len + 2 < bufferLen) {
      strcpy(buffer + offset, buff);
      offset += len + 1;
    }
  }
  buffer[offset++] = '\0';
  buffer[offset++] = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<iniFileGetSection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x424(%rbp)
mov    $0x0,%al
call   1040 <rewindBuffer@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x220(%rbp),%rdi
call   1070 <readLine@plt>
cmp    $0x0,%eax
jge    11fc <iniFileGetSection+0x9c>
mov    -0x18(%rbp),%rax
mov    -0x424(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x424(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x424(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x424(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    12f9 <iniFileGetSection+0x199>
jmp    1201 <iniFileGetSection+0xa1>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    119e <iniFileGetSection+0x3e>
jmp    1223 <iniFileGetSection+0xc3>
lea    -0x220(%rbp),%rdi
call   1070 <readLine@plt>
mov    %eax,%ecx
mov    %ecx,-0x428(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x429(%rbp)
jl     125b <iniFileGetSection+0xfb>
movsbl -0x220(%rbp),%eax
cmp    $0x5b,%eax
setne  %al
mov    %al,-0x429(%rbp)
mov    -0x429(%rbp),%al
test   $0x1,%al
jne    126e <iniFileGetSection+0x10e>
jmp    12ba <iniFileGetSection+0x15a>
mov    -0x424(%rbp),%eax
add    -0x428(%rbp),%eax
add    $0x2,%eax
cmp    -0x1c(%rbp),%eax
jge    12b5 <iniFileGetSection+0x155>
mov    -0x18(%rbp),%rdi
movslq -0x424(%rbp),%rax
add    %rax,%rdi
lea    -0x220(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x428(%rbp),%eax
add    $0x1,%eax
add    -0x424(%rbp),%eax
mov    %eax,-0x424(%rbp)
jmp    1223 <iniFileGetSection+0xc3>
mov    -0x18(%rbp),%rax
mov    -0x424(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x424(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x424(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x424(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniFileGetSection>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <rewindBuffer@plt>
lea    0xe7a(%rip),%rsi
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1080 <sprintf@plt>
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1070 <readLine@plt>
test   %eax,%eax
js     1223 <iniFileGetSection+0xc3>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11a0 <iniFileGetSection+0x40>
mov    %rsp,%rdi
call   1070 <readLine@plt>
xor    %ebp,%ebp
test   %eax,%eax
js     1212 <iniFileGetSection+0xb2>
cmpb   $0x5b,(%rsp)
je     1212 <iniFileGetSection+0xb2>
mov    %eax,%ebx
xor    %ebp,%ebp
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%eax
add    $0x2,%eax
cmp    %r15d,%eax
jge    11fe <iniFileGetSection+0x9e>
movslq %ebp,%rdi
add    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    %ebx,%ebp
add    $0x1,%ebp
mov    %r12,%rdi
call   1070 <readLine@plt>
test   %eax,%eax
js     1212 <iniFileGetSection+0xb2>
mov    %eax,%ebx
cmpb   $0x5b,(%rsp)
jne    11e0 <iniFileGetSection+0x80>
movslq %ebp,%rax
movw   $0x0,(%r14,%rax,1)
mov    $0x1,%eax
jmp    1231 <iniFileGetSection+0xd1>
movw   $0x0,(%r14)
mov    %r14,%rdi
call   1050 <strlen@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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