#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
scalar_t__ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
char *sgets(char *, char *);
scalar_t__ strcasecmp(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncasecmp(char *, char *, int /*<<< orphan*/);
void WriteINIString(char *section, char *key, char *value, char *filename) {
  FILE *fp;
  char *buffer, *p, *p0, s1[80], s2[80], s3[80];
  int tl;
  fp = fopen(filename, "rb");
  if (fp == NULL) {
    fp = fopen(filename, "wb");
    if (fp == NULL)
      return;
    fprintf(fp,
            "[%s]"
            "\r\n",
            section);
    fprintf(fp,
            "%s=%s"
            "\r\n"
            "\r\n",
            key, value);
    fclose(fp);
    return;
  }
  fseek(fp, 0, 2);
  tl = (int)ftell(fp);
  fseek(fp, 0, 0);
  buffer = (char *)malloc(tl + 1);
  if (buffer == NULL) {
    fclose(fp);
    return;
  }
  fread(buffer, tl, 1, fp);
  buffer[tl] = 0;
  fclose(fp);
  strcpy(s2, "[");
  strcat(s2, section);
  strcat(s2, "]");
  strcpy(s3, key);
  strcat(s3, "=");
  p = buffer;
  do {
    p = sgets(p, s1);
    if (strcasecmp(s1, s2) == 0) {
      do {
        p0 = p;
        p = sgets(p, s1);
        if (strncasecmp(s1, s3, strlen(s3)) == 0) {
          fp = fopen(filename, "wb");
          if (fp == NULL) {
            free(buffer);
            return;
          }
          fwrite(buffer, p0 - buffer, 1, fp);
          fprintf(fp,
                  "%s=%s"
                  "\r\n",
                  key, value);
          fwrite(p, tl - (p - buffer), 1, fp);
          fclose(fp);
          free(buffer);
          return;
        }
      } while (s1[0] != 0);
      fp = fopen(filename, "wb");
      if (fp == NULL) {
        free(buffer);
        return;
      }
      fwrite(buffer, p0 - buffer, 1, fp);
      fprintf(fp,
              "%s=%s"
              "\r\n",
              key, value);
      fwrite(p0, tl - (p0 - buffer), 1, fp);
      fclose(fp);
      free(buffer);
      return;
    }
  } while (p < buffer + tl);
  fp = fopen(filename, "wb");
  if (fp == NULL) {
    free(buffer);
    return;
  }
  fprintf(fp,
          "[%s]"
          "\r\n",
          section);
  fprintf(fp,
          "%s=%s"
          "\r\n"
          "\r\n",
          key, value);
  fwrite(buffer, tl, 1, fp);
  fclose(fp);
  free(buffer);
  return;
}


x86 assembly (clang, -O0):
<WriteINIString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    128c <WriteINIString+0x9c>
mov    -0x20(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124e <WriteINIString+0x5e>
jmp    1615 <WriteINIString+0x425>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
jmp    1615 <WriteINIString+0x425>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10e0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0x134(%rbp)
mov    -0x28(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10e0 <fseek@plt>
mov    -0x134(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12e3 <WriteINIString+0xf3>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
jmp    1615 <WriteINIString+0x425>
mov    -0x30(%rbp),%rdi
mov    -0x134(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fread@plt>
mov    -0x30(%rbp),%rax
movslq -0x134(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
lea    -0xe0(%rbp),%rdi
lea    0xcf6(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1100 <strcat@plt>
lea    -0xe0(%rbp),%rdi
lea    0xcd5(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    0xcb4(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10d0 <sgets@plt>
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    156e <WriteINIString+0x37e>
jmp    13aa <WriteINIString+0x1ba>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10d0 <sgets@plt>
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   10c0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    14b3 <WriteINIString+0x2c3>
mov    -0x20(%rbp),%rdi
lea    0xbeb(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    143a <WriteINIString+0x24a>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1615 <WriteINIString+0x425>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xbb1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x38(%rbp),%rdi
movslq -0x134(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1615 <WriteINIString+0x425>
jmp    14b8 <WriteINIString+0x2c8>
movsbl -0x90(%rbp),%eax
cmp    $0x0,%eax
jne    13aa <WriteINIString+0x1ba>
mov    -0x20(%rbp),%rdi
lea    0xb30(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    14f5 <WriteINIString+0x305>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1615 <WriteINIString+0x425>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xaf6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x40(%rbp),%rdi
movslq -0x134(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1615 <WriteINIString+0x425>
jmp    1573 <WriteINIString+0x383>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movslq -0x134(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jb     1374 <WriteINIString+0x184>
mov    -0x20(%rbp),%rdi
lea    0xa6a(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    15bb <WriteINIString+0x3cb>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1615 <WriteINIString+0x425>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xa3c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xa29(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x134(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteINIString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0xdec(%rip),%rsi
mov    %rcx,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     137f <WriteINIString+0x18f>
mov    %rax,%rbx
mov    %rbp,0x18(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10e0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <fseek@plt>
lea    0x1(%rbp),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     13c5 <WriteINIString+0x1d5>
mov    %rax,%r14
mov    %r12,0x10(%rsp)
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
mov    %rbp,(%rsp)
movslq %ebp,%rax
mov    %r14,%rbp
add    %rax,%rbp
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xd78(%rip),%rsi
lea    0xc0(%rsp),%r12
mov    %r12,%rdi
call   1050 <strcpy@plt>
mov    %r12,%rdi
mov    0x18(%rsp),%rsi
call   1100 <strcat@plt>
lea    0xd56(%rip),%rsi
mov    %r12,%rdi
call   1100 <strcat@plt>
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,0x8(%rsp)
mov    %r13,%rsi
call   1050 <strcpy@plt>
lea    0xd34(%rip),%rsi
mov    %rbx,%rdi
call   1100 <strcat@plt>
lea    0x20(%rsp),%rbx
mov    %r14,%r13
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   10d0 <sgets@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     13de <WriteINIString+0x1ee>
cmp    %rbp,%r13
jb     1300 <WriteINIString+0x110>
lea    0xcd5(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     14e6 <WriteINIString+0x2f6>
mov    %rax,%rbx
lea    0xcbd(%rip),%rsi
mov    %rax,%rdi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xcae(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
mov    (%rsp),%rsi
jmp    14d1 <WriteINIString+0x2e1>
lea    0xc7d(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     14ee <WriteINIString+0x2fe>
mov    %rax,%rbx
lea    0xc65(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xc58(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fclose@plt>
lea    0x20(%rsp),%rbx
lea    0x70(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r13,%rbp
mov    %r13,%rdi
mov    %rbx,%rsi
call   10d0 <sgets@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   10c0 <strncasecmp@plt>
test   %rax,%rax
je     147d <WriteINIString+0x28d>
cmpb   $0x0,0x20(%rsp)
jne    13f0 <WriteINIString+0x200>
lea    0xbda(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     14e6 <WriteINIString+0x2f6>
mov    %rax,%rbx
mov    %ebp,%r15d
sub    %r14d,%r15d
mov    %r14,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
lea    0xbc0(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rsp),%rsi
sub    %r15d,%esi
mov    %rbp,%rdi
jmp    14d1 <WriteINIString+0x2e1>
lea    0xb7f(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     14e6 <WriteINIString+0x2f6>
mov    %rax,%rbx
sub    %r14d,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
lea    0xb6d(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rsp),%rsi
add    %r14d,%esi
sub    %r13d,%esi
mov    %r13,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1110 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"[%s]\0D\0A\00"
@.str.3 = [10 x i8] c"%s=%s\0D\0A\0D\0A\00"
@.str.4 = [2 x i8] c"[\00"
@.str.5 = [2 x i8] c"]\00"
@.str.6 = [2 x i8] c"=\00"
@.str.7 = [8 x i8] c"%s=%s\0D\0A\00"
define void @WriteINIString(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [80 x i8]
%14 = alloca [80 x i8]
%15 = alloca [80 x i8]
%16 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%17 = load i8*, i8** %8
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %9
%19 = load i32*, i32** %9
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %37
21: ; preds = %4
%22 = load i8*, i8** %8
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %9
%24 = load i32*, i32** %9
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
br label %212
27: ; preds = %21
%28 = load i32*, i32** %9
%29 = load i8*, i8** %5
%30 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32*, i32** %9
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %32, i8* %33)
%35 = load i32*, i32** %9
%36 = call i32 @fclose(i32* %35)
br label %212
37: ; preds = %4
%38 = load i32*, i32** %9
%39 = call i32 @fseek(i32* %38, i32 0, i32 2)
%40 = load i32*, i32** %9
%41 = call i64 @ftell(i32* %40)
%42 = trunc i64 %41 to i32
store i32 %42, i32* %16
%43 = load i32*, i32** %9
%44 = call i32 @fseek(i32* %43, i32 0, i32 0)
%45 = load i32, i32* %16
%46 = add nsw i32 %45, 1
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %10
%49 = load i8*, i8** %10
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %37
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
br label %212
54: ; preds = %37
%55 = load i8*, i8** %10
%56 = load i32, i32* %16
%57 = load i32*, i32** %9
%58 = call i32 @fread(i8* %55, i32 %56, i32 1, i32* %57)
%59 = load i8*, i8** %10
%60 = load i32, i32* %16
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
%63 = load i32*, i32** %9
%64 = call i32 @fclose(i32* %63)
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%68 = load i8*, i8** %5
%69 = call i32 @strcat(i8* %67, i8* %68)
%70 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%71 = call i32 @strcat(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%73 = load i8*, i8** %6
%74 = call i32 @strcpy(i8* %72, i8* %73)
%75 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%76 = call i32 @strcat(i8* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%77 = load i8*, i8** %10
store i8* %77, i8** %11
br label %78
78: ; preds = %181, %54
%79 = load i8*, i8** %11
%80 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%81 = call i8* @sgets(i8* %79, i8* %80)
store i8* %81, i8** %11
%82 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%83 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%84 = call i64 @strcasecmp(i8* %82, i8* %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %180
86: ; preds = %78
br label %87
87: ; preds = %137, %86
%88 = load i8*, i8** %11
store i8* %88, i8** %12
%89 = load i8*, i8** %11
%90 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%91 = call i8* @sgets(i8* %89, i8* %90)
store i8* %91, i8** %11
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%93 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%94 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%95 = call i32 @strlen(i8* %94)
%96 = call i64 @strncasecmp(i8* %92, i8* %93, i32 %95)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %136
98: ; preds = %87
%99 = load i8*, i8** %8
%100 = call i32* @fopen(i8* %99, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %100, i32** %9
%101 = load i32*, i32** %9
%102 = icmp eq i32* %101, null
br i1 %102, label %103, label %106
103: ; preds = %98
%104 = load i8*, i8** %10
%105 = call i32 @free(i8* %104)
br label %212
106: ; preds = %98
%107 = load i8*, i8** %10
%108 = load i8*, i8** %12
%109 = load i8*, i8** %10
%110 = ptrtoint i8* %108 to i64
%111 = ptrtoint i8* %109 to i64
%112 = sub i64 %110, %111
%113 = trunc i64 %112 to i32
%114 = load i32*, i32** %9
%115 = call i32 @fwrite(i8* %107, i32 %113, i32 1, i32* %114)
%116 = load i32*, i32** %9
%117 = load i8*, i8** %6
%118 = load i8*, i8** %7
%119 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %116, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %117, i8* %118)
%120 = load i8*, i8** %11
%121 = load i32, i32* %16
%122 = sext i32 %121 to i64
%123 = load i8*, i8** %11
%124 = load i8*, i8** %10
%125 = ptrtoint i8* %123 to i64
%126 = ptrtoint i8* %124 to i64
%127 = sub i64 %125, %126
%128 = sub nsw i64 %122, %127
%129 = trunc i64 %128 to i32
%130 = load i32*, i32** %9
%131 = call i32 @fwrite(i8* %120, i32 %129, i32 1, i32* %130)
%132 = load i32*, i32** %9
%133 = call i32 @fclose(i32* %132)
%134 = load i8*, i8** %10
%135 = call i32 @free(i8* %134)
br label %212
136: ; preds = %87
br label %137
137: ; preds = %136
%138 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = icmp ne i32 %140, 0
br i1 %141, label %87, label %142
142: ; preds = %137
%143 = load i8*, i8** %8
%144 = call i32* @fopen(i8* %143, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %144, i32** %9
%145 = load i32*, i32** %9
%146 = icmp eq i32* %145, null
br i1 %146, label %147, label %150
147: ; preds = %142
%148 = load i8*, i8** %10
%149 = call i32 @free(i8* %148)
br label %212
150: ; preds = %142
%151 = load i8*, i8** %10
%152 = load i8*, i8** %12
%153 = load i8*, i8** %10
%154 = ptrtoint i8* %152 to i64
%155 = ptrtoint i8* %153 to i64
%156 = sub i64 %154, %155
%157 = trunc i64 %156 to i32
%158 = load i32*, i32** %9
%159 = call i32 @fwrite(i8* %151, i32 %157, i32 1, i32* %158)
%160 = load i32*, i32** %9
%161 = load i8*, i8** %6
%162 = load i8*, i8** %7
%163 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %160, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %161, i8* %162)
%164 = load i8*, i8** %12
%165 = load i32, i32* %16
%166 = sext i32 %165 to i64
%167 = load i8*, i8** %12
%168 = load i8*, i8** %10
%169 = ptrtoint i8* %167 to i64
%170 = ptrtoint i8* %168 to i64
%171 = sub i64 %169, %170
%172 = sub nsw i64 %166, %171
%173 = trunc i64 %172 to i32
%174 = load i32*, i32** %9
%175 = call i32 @fwrite(i8* %164, i32 %173, i32 1, i32* %174)
%176 = load i32*, i32** %9
%177 = call i32 @fclose(i32* %176)
%178 = load i8*, i8** %10
%179 = call i32 @free(i8* %178)
br label %212
180: ; preds = %78
br label %181
181: ; preds = %180
%182 = load i8*, i8** %11
%183 = load i8*, i8** %10
%184 = load i32, i32* %16
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds i8, i8* %183, i64 %185
%187 = icmp ult i8* %182, %186
br i1 %187, label %78, label %188
188: ; preds = %181
%189 = load i8*, i8** %8
%190 = call i32* @fopen(i8* %189, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %190, i32** %9
%191 = load i32*, i32** %9
%192 = icmp eq i32* %191, null
br i1 %192, label %193, label %196
193: ; preds = %188
%194 = load i8*, i8** %10
%195 = call i32 @free(i8* %194)
br label %212
196: ; preds = %188
%197 = load i32*, i32** %9
%198 = load i8*, i8** %5
%199 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %197, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %198)
%200 = load i32*, i32** %9
%201 = load i8*, i8** %6
%202 = load i8*, i8** %7
%203 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %200, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %201, i8* %202)
%204 = load i8*, i8** %10
%205 = load i32, i32* %16
%206 = load i32*, i32** %9
%207 = call i32 @fwrite(i8* %204, i32 %205, i32 1, i32* %206)
%208 = load i32*, i32** %9
%209 = call i32 @fclose(i32* %208)
%210 = load i8*, i8** %10
%211 = call i32 @free(i8* %210)
br label %212
212: ; preds = %196, %193, %150, %147, %106, %103, %51, %27, %26
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"[%s]\0D\0A\00"
@.str.3 = [10 x i8] c"%s=%s\0D\0A\0D\0A\00"
@.str.4 = [2 x i8] c"[\00"
@.str.5 = [2 x i8] c"]\00"
@.str.6 = [2 x i8] c"=\00"
@.str.7 = [8 x i8] c"%s=%s\0D\0A\00"
define void @WriteINIString(i8* %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = alloca [80 x i8]
%6 = alloca [80 x i8]
%7 = alloca [80 x i8]
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%11 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %4
%14 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %103, label %16
16: ; preds = %13
%17 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%18 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2)
%19 = tail call i32 @fclose(i32* %14)
br label %103
20: ; preds = %4
%21 = tail call i32 @fseek(i32* %11, i32 0, i32 2)
%22 = tail call i64 @ftell(i32* %11)
%23 = trunc i64 %22 to i32
%24 = tail call i32 @fseek(i32* %11, i32 0, i32 0)
%25 = add nsw i32 %23, 1
%26 = tail call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = icmp eq i64 %26, 0
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = tail call i32 @fclose(i32* %11)
br label %103
31: ; preds = %20
%32 = tail call i32 @fread(i8* %27, i32 %23, i32 1, i32* %11)
%33 = shl i64 %22, 32
%34 = ashr exact i64 %33, 32
%35 = getelementptr inbounds i8, i8* %27, i64 %34
store i8 0, i8* %35
%36 = tail call i32 @fclose(i32* %11)
%37 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @strcat(i8* %9, i8* %0)
%39 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @strcpy(i8* %10, i8* %1)
%41 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %42
42: ; preds = %90, %31
%43 = phi i8* [ %27, %31 ], [ %44, %90 ]
%44 = call i8* @sgets(i8* %43, i8* %8)
%45 = call i64 @strcasecmp(i8* %8, i8* %9)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %90
47: ; preds = %42, %71
%48 = phi i8* [ %49, %71 ], [ %44, %42 ]
%49 = call i8* @sgets(i8* %48, i8* %8)
%50 = call i32 @strlen(i8* %10)
%51 = call i64 @strncasecmp(i8* %8, i8* %10, i32 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %71
53: ; preds = %47
%54 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 @free(i8* %27)
br label %103
58: ; preds = %53
%59 = ptrtoint i8* %48 to i64
%60 = sub i64 %59, %26
%61 = trunc i64 %60 to i32
%62 = call i32 @fwrite(i8* %27, i32 %61, i32 1, i32* %54)
%63 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %1, i8* %2)
%64 = ptrtoint i8* %49 to i64
%65 = add i64 %26, %22
%66 = sub i64 %65, %64
%67 = trunc i64 %66 to i32
%68 = call i32 @fwrite(i8* %49, i32 %67, i32 1, i32* %54)
%69 = call i32 @fclose(i32* %54)
%70 = call i32 @free(i8* %27)
br label %103
71: ; preds = %47
%72 = load i8, i8* %8
%73 = icmp eq i8 %72, 0
br i1 %73, label %74, label %47
74: ; preds = %71
%75 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @free(i8* %27)
br label %103
79: ; preds = %74
%80 = ptrtoint i8* %48 to i64
%81 = sub i64 %80, %26
%82 = trunc i64 %81 to i32
%83 = call i32 @fwrite(i8* %27, i32 %82, i32 1, i32* %75)
%84 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %1, i8* %2)
%85 = sub i64 %22, %81
%86 = trunc i64 %85 to i32
%87 = call i32 @fwrite(i8* %48, i32 %86, i32 1, i32* %75)
%88 = call i32 @fclose(i32* %75)
%89 = call i32 @free(i8* %27)
br label %103
90: ; preds = %42
%91 = icmp ult i8* %44, %35
br i1 %91, label %42, label %92
92: ; preds = %90
%93 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%94 = icmp eq i32* %93, null
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 @free(i8* %27)
br label %103
97: ; preds = %92
%98 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%99 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2)
%100 = call i32 @fwrite(i8* %27, i32 %23, i32 1, i32* %93)
%101 = call i32 @fclose(i32* %93)
%102 = call i32 @free(i8* %27)
br label %103
103: ; preds = %13, %97, %95, %79, %77, %58, %56, %29, %16
ret void
}