#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*/ mkstemp(char *);
scalar_t__ read_line(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ unlink(char *);
int WritePrivateProfileString(char *section, char *entry, char *buffer,
                              char *file_name) {
  FILE *rfp, *wfp;
  char tmp_name[15];
  char buff[180];
  char t_section[180];
  int len = strlen(entry);
  mkstemp(tmp_name);
  sprintf(t_section, "[%s]", section);
  if (!(rfp = fopen(file_name, "r"))) {
    if (!(wfp = fopen(file_name, "w")))
      return 0;
    fprintf(wfp, "%s\n", t_section);
    fprintf(wfp, "%s=%s\n", entry, buffer);
    fclose(wfp);
    return 1;
  }
  if (!(wfp = fopen(tmp_name, "w"))) {
    fclose(wfp);
    return 0;
  }
  do {
    if (!read_line(rfp, buff)) {
      fprintf(wfp, "\n%s\n", t_section);
      fprintf(wfp, "%s=%s\n", entry, buffer);
      fclose(rfp);
      fclose(wfp);
      unlink(file_name);
      rename(tmp_name, file_name);
      return 1;
    }
    fprintf(wfp, "%s\n", buff);
  } while (strcmp(buff, t_section));
  while (1) {
    if (!read_line(rfp, buff)) {
      fprintf(wfp, "%s=%s\n", entry, buffer);
      fclose(rfp);
      fclose(wfp);
      unlink(file_name);
      rename(tmp_name, file_name);
      return 1;
    }
    if (!strncmp(buff, entry, len) || buff[0] == '\0')
      break;
    fprintf(wfp, "%s\n", buff);
  }
  if (buff[0] == '\0') {
    fprintf(wfp, "%s=%s\n", entry, buffer);
    do {
      fprintf(wfp, "%s\n", buff);
    } while (read_line(rfp, buff));
  } else {
    fprintf(wfp, "%s=%s\n", entry, buffer);
    while (read_line(rfp, buff))
      fprintf(wfp, "%s\n", buff);
  }
  fclose(rfp);
  fclose(wfp);
  unlink(file_name);
  rename(tmp_name, file_name);
  return 1;
}


x86 assembly (clang, -O0):
<WritePrivateProfileString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c4(%rbp)
lea    -0x47(%rbp),%rdi
call   1090 <mkstemp@plt>
lea    -0x1c0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    128a <WritePrivateProfileString+0xda>
mov    -0x28(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1242 <WritePrivateProfileString+0x92>
movl   $0x0,-0x4(%rbp)
jmp    1520 <WritePrivateProfileString+0x370>
mov    -0x38(%rbp),%rdi
lea    -0x1c0(%rbp),%rdx
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1520 <WritePrivateProfileString+0x370>
lea    -0x47(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    12bd <WritePrivateProfileString+0x10d>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1520 <WritePrivateProfileString+0x370>
jmp    12c2 <WritePrivateProfileString+0x112>
mov    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   10a0 <read_line@plt>
cmp    $0x0,%rax
jne    1343 <WritePrivateProfileString+0x193>
mov    -0x38(%rbp),%rdi
lea    -0x1c0(%rbp),%rdx
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x47(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <rename@plt>
movl   $0x1,-0x4(%rbp)
jmp    1520 <WritePrivateProfileString+0x370>
mov    -0x38(%rbp),%rdi
lea    -0x100(%rbp),%rdx
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x100(%rbp),%rdi
lea    -0x1c0(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12c2 <WritePrivateProfileString+0x112>
jmp    137e <WritePrivateProfileString+0x1ce>
mov    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   10a0 <read_line@plt>
cmp    $0x0,%rax
jne    13e6 <WritePrivateProfileString+0x236>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xc5e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x47(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <rename@plt>
movl   $0x1,-0x4(%rbp)
jmp    1520 <WritePrivateProfileString+0x370>
lea    -0x100(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c4(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     1415 <WritePrivateProfileString+0x265>
movsbl -0x100(%rbp),%eax
cmp    $0x0,%eax
jne    141a <WritePrivateProfileString+0x26a>
jmp    1438 <WritePrivateProfileString+0x288>
mov    -0x38(%rbp),%rdi
lea    -0x100(%rbp),%rdx
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    137e <WritePrivateProfileString+0x1ce>
movsbl -0x100(%rbp),%eax
cmp    $0x0,%eax
jne    149a <WritePrivateProfileString+0x2ea>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xbae(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x100(%rbp),%rdx
lea    0xb9d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   10a0 <read_line@plt>
cmp    $0x0,%rax
jne    1462 <WritePrivateProfileString+0x2b2>
jmp    14f1 <WritePrivateProfileString+0x341>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xb5c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   10a0 <read_line@plt>
cmp    $0x0,%rax
je     14ec <WritePrivateProfileString+0x33c>
mov    -0x38(%rbp),%rdi
lea    -0x100(%rbp),%rdx
lea    0xb31(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    14b4 <WritePrivateProfileString+0x304>
jmp    14f1 <WritePrivateProfileString+0x341>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x47(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <rename@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WritePrivateProfileString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <strlen@plt>
mov    %eax,0x1c(%rsp)
lea    0x21(%rsp),%rdi
call   1090 <mkstemp@plt>
lea    0xe16(%rip),%rsi
lea    0xf0(%rsp),%rdi
mov    %rbx,%rdx
call   10d0 <sprintf@plt>
lea    0xe04(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12f6 <WritePrivateProfileString+0x146>
mov    %rax,%r14
lea    0xdeb(%rip),%rsi
lea    0x21(%rsp),%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     134b <WritePrivateProfileString+0x19b>
mov    %rax,%r15
mov    %r12,0x10(%rsp)
mov    %rbp,0x8(%rsp)
lea    0x30(%rsp),%rbp
lea    0xdc9(%rip),%r12
lea    0xf0(%rsp),%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <read_line@plt>
test   %rax,%rax
je     1356 <WritePrivateProfileString+0x1a6>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1250 <WritePrivateProfileString+0xa0>
lea    0x30(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <read_line@plt>
test   %rax,%rax
je     136f <WritePrivateProfileString+0x1bf>
lea    0x30(%rsp),%r12
lea    0xd6b(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    0x1c(%rsp),%edx
call   1040 <strncmp@plt>
movzbl 0x30(%rsp),%ebx
test   %eax,%eax
je     13cf <WritePrivateProfileString+0x21f>
test   %bl,%bl
je     13cf <WritePrivateProfileString+0x21f>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   10a0 <read_line@plt>
test   %rax,%rax
jne    12b0 <WritePrivateProfileString+0x100>
jmp    136f <WritePrivateProfileString+0x1bf>
lea    0xd0a(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13cb <WritePrivateProfileString+0x21b>
mov    %rax,%rbx
lea    0xcf9(%rip),%rsi
lea    0xf0(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xcd8(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    13b2 <WritePrivateProfileString+0x202>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <fclose@plt>
jmp    13b7 <WritePrivateProfileString+0x207>
lea    0xcb3(%rip),%rsi
lea    0xf0(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xc93(%rip),%rsi
mov    %r15,%rdi
mov    %r13,%rdx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0x21(%rsp),%rdi
mov    %rbx,%rsi
call   10c0 <rename@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    13b7 <WritePrivateProfileString+0x207>
lea    0xc33(%rip),%rsi
mov    %r15,%rdi
mov    %r13,%rdx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %bl,%bl
je     1432 <WritePrivateProfileString+0x282>
lea    0x30(%rsp),%rsi
mov    %r14,%rdi
call   10a0 <read_line@plt>
test   %rax,%rax
mov    0x8(%rsp),%r12
je     1470 <WritePrivateProfileString+0x2c0>
lea    0xc07(%rip),%rbx
lea    0x30(%rsp),%rbp
nop
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <read_line@plt>
test   %rax,%rax
jne    1410 <WritePrivateProfileString+0x260>
jmp    1470 <WritePrivateProfileString+0x2c0>
lea    0xbd8(%rip),%rbx
lea    0x30(%rsp),%rbp
mov    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10a0 <read_line@plt>
test   %rax,%rax
jne    1450 <WritePrivateProfileString+0x2a0>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1030 <unlink@plt>
lea    0x21(%rsp),%rdi
mov    %r12,%rsi
jmp    13ad <WritePrivateProfileString+0x1fd>

LLVM IR (-O0):
@.str = [5 x i8] c"[%s]\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [7 x i8] c"%s=%s\0A\00"
@.str.5 = [5 x i8] c"\0A%s\0A\00"
define i32 @WritePrivateProfileString(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [15 x i8]
%13 = alloca [180 x i8]
%14 = alloca [180 x i8]
%15 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %15
%18 = getelementptr inbounds [15 x i8], [15 x i8]* %12, i64 0, i64 0
%19 = call i32 @mkstemp(i8* %18)
%20 = getelementptr inbounds [180 x i8], [180 x i8]* %14, i64 0, i64 0
%21 = load i8*, i8** %6
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %9
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %10
%25 = icmp ne i32* %24, null
br i1 %25, label %41, label %26
26: ; preds = %4
%27 = load i8*, i8** %9
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %11
%29 = icmp ne i32* %28, null
br i1 %29, label %31, label %30
30: ; preds = %26
store i32 0, i32* %5
br label %161
31: ; preds = %26
%32 = load i32*, i32** %11
%33 = getelementptr inbounds [180 x i8], [180 x i8]* %14, i64 0, i64 0
%34 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %11
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %36, i8* %37)
%39 = load i32*, i32** %11
%40 = call i32 @fclose(i32* %39)
store i32 1, i32* %5
br label %161
41: ; preds = %4
%42 = getelementptr inbounds [15 x i8], [15 x i8]* %12, i64 0, i64 0
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %43, i32** %11
%44 = icmp ne i32* %43, null
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i32*, i32** %11
%47 = call i32 @fclose(i32* %46)
store i32 0, i32* %5
br label %161
48: ; preds = %41
br label %49
49: ; preds = %75, %48
%50 = load i32*, i32** %10
%51 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%52 = call i64 @read_line(i32* %50, i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %71, label %54
54: ; preds = %49
%55 = load i32*, i32** %11
%56 = getelementptr inbounds [180 x i8], [180 x i8]* %14, i64 0, i64 0
%57 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %11
%59 = load i8*, i8** %7
%60 = load i8*, i8** %8
%61 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %59, i8* %60)
%62 = load i32*, i32** %10
%63 = call i32 @fclose(i32* %62)
%64 = load i32*, i32** %11
%65 = call i32 @fclose(i32* %64)
%66 = load i8*, i8** %9
%67 = call i32 @unlink(i8* %66)
%68 = getelementptr inbounds [15 x i8], [15 x i8]* %12, i64 0, i64 0
%69 = load i8*, i8** %9
%70 = call i32 @rename(i8* %68, i8* %69)
store i32 1, i32* %5
br label %161
71: ; preds = %49
%72 = load i32*, i32** %11
%73 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%74 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %71
%76 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%77 = getelementptr inbounds [180 x i8], [180 x i8]* %14, i64 0, i64 0
%78 = call i64 @strcmp(i8* %76, i8* %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %49, label %80
80: ; preds = %75
br label %81
81: ; preds = %80, %112
%82 = load i32*, i32** %10
%83 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%84 = call i64 @read_line(i32* %82, i8* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %100, label %86
86: ; preds = %81
%87 = load i32*, i32** %11
%88 = load i8*, i8** %7
%89 = load i8*, i8** %8
%90 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %88, i8* %89)
%91 = load i32*, i32** %10
%92 = call i32 @fclose(i32* %91)
%93 = load i32*, i32** %11
%94 = call i32 @fclose(i32* %93)
%95 = load i8*, i8** %9
%96 = call i32 @unlink(i8* %95)
%97 = getelementptr inbounds [15 x i8], [15 x i8]* %12, i64 0, i64 0
%98 = load i8*, i8** %9
%99 = call i32 @rename(i8* %97, i8* %98)
store i32 1, i32* %5
br label %161
100: ; preds = %81
%101 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%102 = load i8*, i8** %7
%103 = load i32, i32* %15
%104 = call i32 @strncmp(i8* %101, i8* %102, i32 %103)
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %100
%107 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %109, 0
br i1 %110, label %111, label %112
111: ; preds = %106, %100
br label %116
112: ; preds = %106
%113 = load i32*, i32** %11
%114 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%115 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %114)
br label %81
116: ; preds = %111
%117 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%118 = load i8, i8* %117
%119 = sext i8 %118 to i32
%120 = icmp eq i32 %119, 0
br i1 %120, label %121, label %136
121: ; preds = %116
%122 = load i32*, i32** %11
%123 = load i8*, i8** %7
%124 = load i8*, i8** %8
%125 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %122, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %123, i8* %124)
br label %126
126: ; preds = %130, %121
%127 = load i32*, i32** %11
%128 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%129 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %127, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %128)
br label %130
130: ; preds = %126
%131 = load i32*, i32** %10
%132 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%133 = call i64 @read_line(i32* %131, i8* %132)
%134 = icmp ne i64 %133, 0
br i1 %134, label %126, label %135
135: ; preds = %130
br label %151
136: ; preds = %116
%137 = load i32*, i32** %11
%138 = load i8*, i8** %7
%139 = load i8*, i8** %8
%140 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %137, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %138, i8* %139)
br label %141
141: ; preds = %146, %136
%142 = load i32*, i32** %10
%143 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%144 = call i64 @read_line(i32* %142, i8* %143)
%145 = icmp ne i64 %144, 0
br i1 %145, label %146, label %150
146: ; preds = %141
%147 = load i32*, i32** %11
%148 = getelementptr inbounds [180 x i8], [180 x i8]* %13, i64 0, i64 0
%149 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %147, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %148)
br label %141
150: ; preds = %141
br label %151
151: ; preds = %150, %135
%152 = load i32*, i32** %10
%153 = call i32 @fclose(i32* %152)
%154 = load i32*, i32** %11
%155 = call i32 @fclose(i32* %154)
%156 = load i8*, i8** %9
%157 = call i32 @unlink(i8* %156)
%158 = getelementptr inbounds [15 x i8], [15 x i8]* %12, i64 0, i64 0
%159 = load i8*, i8** %9
%160 = call i32 @rename(i8* %158, i8* %159)
store i32 1, i32* %5
br label %161
161: ; preds = %151, %86, %54, %45, %31, %30
%162 = load i32, i32* %5
ret i32 %162
}

LLVM IR (-O2):
@.str = [5 x i8] c"[%s]\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [7 x i8] c"%s=%s\0A\00"
@.str.5 = [5 x i8] c"\0A%s\0A\00"
define i32 @WritePrivateProfileString(i8* %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = alloca [15 x i8]
%6 = alloca [180 x i8]
%7 = alloca [180 x i8]
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [180 x i8], [180 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [180 x i8], [180 x i8]* %7, i64 0, i64 0
%11 = tail call i32 @strlen(i8* %1)
%12 = call i32 @mkstemp(i8* %8)
%13 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %23
16: ; preds = %4
%17 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %79, label %19
19: ; preds = %16
%20 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%21 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
%22 = call i32 @fclose(i32* %17)
br label %79
23: ; preds = %4
%24 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @fclose(i32* null)
br label %79
28: ; preds = %23, %38
%29 = call i64 @read_line(i32* %14, i8* %9)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%33 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
%34 = call i32 @fclose(i32* %14)
%35 = call i32 @fclose(i32* %24)
%36 = call i32 @unlink(i8* %3)
%37 = call i32 @rename(i8* %8, i8* %3)
br label %79
38: ; preds = %28
%39 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%40 = call i64 @strcmp(i8* %9, i8* %10)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %28
42: ; preds = %38
%43 = call i64 @read_line(i32* %14, i8* %9)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %57, %42
%46 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
%47 = call i32 @fclose(i32* %14)
%48 = call i32 @fclose(i32* %24)
%49 = call i32 @unlink(i8* %3)
%50 = call i32 @rename(i8* %8, i8* %3)
br label %79
51: ; preds = %42, %57
%52 = call i32 @strncmp(i8* %9, i8* %1, i32 %11)
%53 = icmp eq i32 %52, 0
%54 = load i8, i8* %9
%55 = icmp eq i8 %54, 0
%56 = select i1 %53, i1 true, i1 %55
br i1 %56, label %61, label %57
57: ; preds = %51
%58 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%59 = call i64 @read_line(i32* %14, i8* %9)
%60 = icmp eq i64 %59, 0
br i1 %60, label %45, label %51
61: ; preds = %51
%62 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
br i1 %55, label %63, label %67
63: ; preds = %61, %63
%64 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%65 = call i64 @read_line(i32* %14, i8* %9)
%66 = icmp eq i64 %65, 0
br i1 %66, label %74, label %63
67: ; preds = %61
%68 = call i64 @read_line(i32* %14, i8* %9)
%69 = icmp eq i64 %68, 0
br i1 %69, label %74, label %70
70: ; preds = %67, %70
%71 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%72 = call i64 @read_line(i32* %14, i8* %9)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %70
74: ; preds = %70, %63, %67
%75 = call i32 @fclose(i32* %14)
%76 = call i32 @fclose(i32* %24)
%77 = call i32 @unlink(i8* %3)
%78 = call i32 @rename(i8* %8, i8* %3)
br label %79
79: ; preds = %16, %74, %45, %31, %26, %19
%80 = phi i32 [ 1, %74 ], [ 1, %45 ], [ 1, %31 ], [ 0, %26 ], [ 1, %19 ], [ 0, %16 ]
ret i32 %80
}