#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 /*<<< orphan*/ createWriteBuffer();
int /*<<< orphan*/ destroyWriteBuffer();
int readLine(char *);
int /*<<< orphan*/ rewindBuffer();
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ writeLine(char *);
int iniFileWriteSection(char *section, char *buffer) {
  char buff[512];
  char t_section[512];
  int len;
  rewindBuffer();
  createWriteBuffer();
  sprintf(t_section, "[%s]", section);
  while (readLine(buff) >= 0 && strcmp(buff, t_section) != 0) {
    writeLine(buff);
    writeLine("\n");
  }
  writeLine(t_section);
  writeLine("\n");
  while (*buffer != '\0') {
    writeLine(buffer);
    writeLine("\n");
    buffer += strlen(buffer) + 1;
  }
  while ((len = readLine(buff)) >= 0 && buff[0] != '\0' && buff[0] != '[')
    ;
  while (len >= 0) {
    writeLine(buff);
    writeLine("\n");
    len = readLine(buff);
  }
  destroyWriteBuffer();
  return 1;
}


x86 assembly (clang, -O0):
<iniFileWriteSection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rewindBuffer@plt>
mov    $0x0,%al
call   1080 <createWriteBuffer@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe4d(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1070 <readLine@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x415(%rbp)
jl     11f7 <iniFileWriteSection+0x77>
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x415(%rbp)
mov    -0x415(%rbp),%al
test   $0x1,%al
jne    120a <iniFileWriteSection+0x8a>
jmp    1227 <iniFileWriteSection+0xa7>
lea    -0x210(%rbp),%rdi
call   1040 <writeLine@plt>
lea    0xde8(%rip),%rdi
call   1040 <writeLine@plt>
jmp    11b8 <iniFileWriteSection+0x38>
lea    -0x410(%rbp),%rdi
call   1040 <writeLine@plt>
lea    0xdcb(%rip),%rdi
call   1040 <writeLine@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     127e <iniFileWriteSection+0xfe>
mov    -0x10(%rbp),%rdi
call   1040 <writeLine@plt>
lea    0xda6(%rip),%rdi
call   1040 <writeLine@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    123f <iniFileWriteSection+0xbf>
jmp    1283 <iniFileWriteSection+0x103>
lea    -0x210(%rbp),%rdi
call   1070 <readLine@plt>
mov    %eax,%ecx
mov    %ecx,-0x414(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x416(%rbp)
jl     12d3 <iniFileWriteSection+0x153>
movsbl -0x210(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x416(%rbp)
je     12d3 <iniFileWriteSection+0x153>
movsbl -0x210(%rbp),%eax
cmp    $0x5b,%eax
setne  %al
mov    %al,-0x416(%rbp)
mov    -0x416(%rbp),%al
test   $0x1,%al
jne    12e6 <iniFileWriteSection+0x166>
jmp    12eb <iniFileWriteSection+0x16b>
jmp    1283 <iniFileWriteSection+0x103>
jmp    12f0 <iniFileWriteSection+0x170>
cmpl   $0x0,-0x414(%rbp)
jl     132c <iniFileWriteSection+0x1ac>
lea    -0x210(%rbp),%rdi
call   1040 <writeLine@plt>
lea    0xcf5(%rip),%rdi
call   1040 <writeLine@plt>
lea    -0x210(%rbp),%rdi
call   1070 <readLine@plt>
mov    %eax,-0x414(%rbp)
jmp    12f0 <iniFileWriteSection+0x170>
mov    $0x0,%al
call   1090 <destroyWriteBuffer@plt>
mov    $0x1,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniFileWriteSection>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <rewindBuffer@plt>
xor    %eax,%eax
call   1080 <createWriteBuffer@plt>
lea    0xe57(%rip),%rsi
lea    0x200(%rsp),%rdi
mov    %r14,%rdx
call   10a0 <sprintf@plt>
mov    %rsp,%rdi
call   1070 <readLine@plt>
test   %eax,%eax
js     120c <iniFileWriteSection+0x8c>
mov    %rsp,%r14
lea    0x200(%rsp),%r15
lea    0xe2e(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120c <iniFileWriteSection+0x8c>
mov    %r14,%rdi
call   1040 <writeLine@plt>
mov    %r12,%rdi
call   1040 <writeLine@plt>
mov    %r14,%rdi
call   1070 <readLine@plt>
test   %eax,%eax
jns    11e0 <iniFileWriteSection+0x60>
lea    0x200(%rsp),%rdi
call   1040 <writeLine@plt>
lea    0xde5(%rip),%rdi
call   1040 <writeLine@plt>
cmpb   $0x0,(%rbx)
je     1264 <iniFileWriteSection+0xe4>
lea    0xdd4(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <writeLine@plt>
mov    %r14,%rdi
call   1040 <writeLine@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmpb   $0x0,0x1(%rax,%rbx,1)
lea    0x1(%rax,%rbx,1),%rbx
jne    1240 <iniFileWriteSection+0xc0>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <readLine@plt>
test   %eax,%eax
js     12bc <iniFileWriteSection+0x13c>
movzbl (%rsp),%eax
cmp    $0x5b,%al
je     1288 <iniFileWriteSection+0x108>
test   %al,%al
jne    1270 <iniFileWriteSection+0xf0>
mov    %rsp,%rbx
lea    0xd73(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <writeLine@plt>
mov    %r14,%rdi
call   1040 <writeLine@plt>
mov    %rbx,%rdi
call   1070 <readLine@plt>
test   %eax,%eax
jns    12a0 <iniFileWriteSection+0x120>
xor    %eax,%eax
call   1090 <destroyWriteBuffer@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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