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


x86 assembly (clang, -O0):
<iniFileWriteString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rewindBuffer@plt>
mov    $0x0,%al
call   1090 <createWriteBuffer@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x620(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x620(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x624(%rbp)
lea    -0x220(%rbp),%rdi
call   1080 <readLine@plt>
cmp    $0x0,%rax
jge    1257 <iniFileWriteString+0xc7>
lea    -0x420(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xdeb(%rip),%rdi
call   1050 <writeLine@plt>
lea    -0x620(%rbp),%rdi
call   1050 <writeLine@plt>
mov    -0x20(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xdca(%rip),%rdi
call   1050 <writeLine@plt>
mov    $0x0,%al
call   10a0 <destroyWriteBuffer@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d2 <iniFileWriteString+0x242>
lea    -0x220(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xd9f(%rip),%rdi
call   1050 <writeLine@plt>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11f5 <iniFileWriteString+0x65>
jmp    1291 <iniFileWriteString+0x101>
lea    -0x220(%rbp),%rdi
call   1080 <readLine@plt>
cmp    $0x0,%rax
jge    12db <iniFileWriteString+0x14b>
lea    -0x620(%rbp),%rdi
call   1050 <writeLine@plt>
mov    -0x20(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xd46(%rip),%rdi
call   1050 <writeLine@plt>
mov    $0x0,%al
call   10a0 <destroyWriteBuffer@plt>
movl   $0x1,-0x4(%rbp)
jmp    13d2 <iniFileWriteString+0x242>
lea    -0x220(%rbp),%rdi
lea    -0x620(%rbp),%rsi
mov    -0x624(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     130e <iniFileWriteString+0x17e>
movsbl -0x220(%rbp),%eax
cmp    $0x5b,%eax
jne    1313 <iniFileWriteString+0x183>
jmp    1330 <iniFileWriteString+0x1a0>
lea    -0x220(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xce3(%rip),%rdi
call   1050 <writeLine@plt>
jmp    1291 <iniFileWriteString+0x101>
lea    -0x620(%rbp),%rdi
call   1050 <writeLine@plt>
mov    -0x20(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xcbd(%rip),%rdi
call   1050 <writeLine@plt>
lea    -0x220(%rbp),%rdi
lea    -0x620(%rbp),%rsi
mov    -0x624(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     138c <iniFileWriteString+0x1fc>
lea    -0x220(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xc82(%rip),%rdi
call   1050 <writeLine@plt>
jmp    1391 <iniFileWriteString+0x201>
lea    -0x220(%rbp),%rdi
call   1080 <readLine@plt>
cmp    $0x0,%rax
jl     13c4 <iniFileWriteString+0x234>
lea    -0x220(%rbp),%rdi
call   1050 <writeLine@plt>
lea    0xc4f(%rip),%rdi
call   1050 <writeLine@plt>
jmp    1391 <iniFileWriteString+0x201>
mov    $0x0,%al
call   10a0 <destroyWriteBuffer@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iniFileWriteString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x608,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <rewindBuffer@plt>
xor    %eax,%eax
call   1090 <createWriteBuffer@plt>
lea    0xe41(%rip),%rsi
lea    0x400(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rdx
call   10b0 <sprintf@plt>
lea    0xe2c(%rip),%rsi
lea    0x200(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %rsp,%rbp
lea    0xe08(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1080 <readLine@plt>
test   %rax,%rax
js     1298 <iniFileWriteString+0x108>
mov    %rbp,%rdi
call   1050 <writeLine@plt>
mov    %rbx,%rdi
call   1050 <writeLine@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1210 <iniFileWriteString+0x80>
mov    %rsp,%rdi
call   1080 <readLine@plt>
test   %rax,%rax
js     12b1 <iniFileWriteString+0x121>
mov    %rsp,%rbx
lea    0x200(%rsp),%r15
lea    0xdad(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12f0 <iniFileWriteString+0x160>
cmpb   $0x5b,(%rsp)
je     12f0 <iniFileWriteString+0x160>
mov    %rbx,%rdi
call   1050 <writeLine@plt>
mov    %r12,%rdi
call   1050 <writeLine@plt>
mov    %rbx,%rdi
call   1080 <readLine@plt>
test   %rax,%rax
jns    1260 <iniFileWriteString+0xd0>
jmp    12b1 <iniFileWriteString+0x121>
lea    0x400(%rsp),%rdi
call   1050 <writeLine@plt>
lea    0xd5d(%rip),%rdi
call   1050 <writeLine@plt>
lea    0x200(%rsp),%rdi
call   1050 <writeLine@plt>
mov    %r14,%rdi
call   1050 <writeLine@plt>
lea    0xd3c(%rip),%rdi
call   1050 <writeLine@plt>
xor    %eax,%eax
call   10a0 <destroyWriteBuffer@plt>
mov    $0x1,%eax
add    $0x608,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <writeLine@plt>
mov    %r14,%rdi
call   1050 <writeLine@plt>
lea    0xcfa(%rip),%rdi
call   1050 <writeLine@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     133b <iniFileWriteString+0x1ab>
mov    %rsp,%rdi
call   1050 <writeLine@plt>
lea    0xcd3(%rip),%rdi
call   1050 <writeLine@plt>
mov    %rsp,%rdi
call   1080 <readLine@plt>
test   %rax,%rax
js     12d2 <iniFileWriteString+0x142>
mov    %rsp,%rbx
lea    0xcb7(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <writeLine@plt>
mov    %rbp,%rdi
call   1050 <writeLine@plt>
mov    %rbx,%rdi
call   1080 <readLine@plt>
test   %rax,%rax
jns    1360 <iniFileWriteString+0x1d0>
jmp    12d2 <iniFileWriteString+0x142>

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

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