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

/* Variables and functions */
int /*<<< orphan*/ WrMessage(char *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
char *strerror(int);
char *tmpnam(char *);
void WrFileTest(void) {
  FILE *pfile;
  FILE *pfile2;
  char *pname;
  char string[20];
  char tmp_file[256];
  int err_no;
  WrMessage("@FILE-HANDLING");
  WrMessage("@FILE-EMPTY-NAME");
  errno = 0;
  pfile = fopen("", "r");
  err_no = errno;
  if (pfile == NULL) {
    WrMessage("@FILE-EMPTY-NAME-NULL");
    printf("System error: %s\n", strerror(err_no));
  } else {
    WrMessage("@FILE-EMPTY-NAME-SUCCESS");
    printf("System error: %s\n", strerror(err_no));
    fclose(pfile);
  }
  printf("\n");
  WrMessage("@FILE-OPEN-TWICE");
  errno = 0;
  pname = tmpnam(tmp_file);
  err_no = errno;
  if (pname != NULL) {
    errno = 0;
    pfile = fopen(tmp_file, "w");
    err_no = errno;
    if (pfile == NULL) {
      WrMessage("@FILE-OPEN-ONCE-ERROR");
      printf("System error: %s\n", strerror(err_no));
    } else {
      pfile2 = fopen(tmp_file, "w");
      err_no = errno;
      if (pfile2 == NULL) {
        WrMessage("@FILE-OPEN-TWICE-ERROR");
        printf("System error: %s\n", strerror(err_no));
      } else {
        WrMessage("@FILE-OPEN-TWICE-NO-ERROR");
        printf("System error: %s\n", strerror(err_no));
        fclose(pfile2);
      }
      fclose(pfile);
      pfile = fopen(tmp_file, "r");
      if (pfile != NULL) {
        fclose(pfile);
        remove(tmp_file);
      }
    }
  } else {
    WrMessage("@FILE-TMP-NAME-ERROR");
    printf("System error: %s\n", strerror(err_no));
    fclose(pfile);
  }
  printf("\n");
  WrMessage("@FILE-MIX-FORMATTED-BINARY");
  errno = 0;
  pname = tmpnam(tmp_file);
  err_no = errno;
  if (pname != NULL) {
    errno = 0;
    pfile = fopen(tmp_file, "wb");
    err_no = errno;
    if (pfile == NULL) {
      WrMessage("@FILE-OPEN-ONCE-ERROR");
      printf("System error: %s\n", strerror(err_no));
    } else {
      fwrite(tmp_file, 1, sizeof(tmp_file), pfile);
      fclose(pfile);
      errno = 0;
      pfile = fopen(tmp_file, "r");
      err_no = errno;
      if (pfile == NULL) {
        WrMessage("@FILE-MIX-REOPEN-ERROR");
        printf("System error: %s\n", strerror(err_no));
      } else {
        errno = 0;
        fgets(string, 20, pfile);
        err_no = errno;
        if (feof(pfile) == 0 && ferror(pfile) == 0) {
          WrMessage("@FILE-MIX-READ-NO-ERROR");
        } else {
          WrMessage("@FILE-MIX-READ-NO-ERROR");
          printf("System error: %s\n", strerror(err_no));
        }
        fclose(pfile);
      }
      remove(tmp_file);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<WrFileTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
lea    0xe3e(%rip),%rdi
call   10b0 <WrMessage@plt>
lea    0xe41(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    0x2e06(%rip),%rax
movl   $0x0,(%rax)
lea    0xe62(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    123e <WrFileTest+0x8e>
lea    0xe0a(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    126f <WrFileTest+0xbf>
lea    0xe05(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xddf(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    0x2d50(%rip),%rax
movl   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
call   10c0 <tmpnam@plt>
mov    %rax,-0x18(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1404 <WrFileTest+0x254>
mov    0x2d19(%rip),%rax
movl   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    132b <WrFileTest+0x17b>
lea    0xd71(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13ff <WrFileTest+0x24f>
lea    -0x130(%rbp),%rdi
lea    0xd3b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    0x2c97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1389 <WrFileTest+0x1d9>
lea    0xd29(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13ba <WrFileTest+0x20a>
lea    0xd13(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc8e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x130(%rbp),%rdi
lea    0xc4f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     13fa <WrFileTest+0x24a>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x130(%rbp),%rdi
call   1030 <remove@plt>
jmp    13ff <WrFileTest+0x24f>
jmp    1435 <WrFileTest+0x285>
lea    0xcb2(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xc0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc88(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    0x2b8a(%rip),%rax
movl   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
call   10c0 <tmpnam@plt>
mov    %rax,-0x18(%rbp)
mov    0x2b6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1626 <WrFileTest+0x476>
mov    0x2b53(%rip),%rax
movl   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
lea    0xc4c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    0x2b2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    14f1 <WrFileTest+0x341>
lea    0xbab(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1621 <WrFileTest+0x471>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   10a0 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2ac5(%rip),%rax
movl   $0x0,(%rax)
lea    -0x130(%rbp),%rdi
lea    0xaf1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    0x2aa1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    157f <WrFileTest+0x3cf>
lea    0xb97(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xac5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1615 <WrFileTest+0x465>
mov    0x2a5a(%rip),%rax
movl   $0x0,(%rax)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x14,%esi
call   1070 <fgets@plt>
mov    0x2a3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
jne    15e4 <WrFileTest+0x434>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
jne    15e4 <WrFileTest+0x434>
lea    0xb2d(%rip),%rdi
call   10b0 <WrMessage@plt>
jmp    160c <WrFileTest+0x45c>
lea    0xb1c(%rip),%rdi
call   10b0 <WrMessage@plt>
mov    -0x134(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xa33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x130(%rbp),%rdi
call   1030 <remove@plt>
jmp    1626 <WrFileTest+0x476>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrFileTest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x128,%rsp
lea    0xe2c(%rip),%rdi
call   10c0 <WrMessage@plt>
lea    0xe2f(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    0x2df4(%rip),%r15
movl   $0x0,(%r15)
lea    0xe4f(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    (%r15),%ebp
test   %rax,%rax
je     123f <WrFileTest+0x7f>
lea    0xe32(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xe0d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    1263 <WrFileTest+0xa3>
lea    0xddc(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xddf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdef(%rip),%rdi
call   10c0 <WrMessage@plt>
movl   $0x0,(%r15)
lea    0x20(%rsp),%rdi
call   10d0 <tmpnam@plt>
test   %rax,%rax
je     1301 <WrFileTest+0x141>
movl   $0x0,(%r15)
lea    0xdd7(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1332 <WrFileTest+0x172>
mov    %rax,%r14
lea    0xdba(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10a0 <fopen@plt>
mov    (%r15),%ebp
test   %rax,%rax
je     135b <WrFileTest+0x19b>
mov    %rax,%rbx
lea    0xdc9(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xd4b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    137f <WrFileTest+0x1bf>
mov    (%r15),%ebp
lea    0xdb2(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xd1a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    13af <WrFileTest+0x1ef>
mov    (%r15),%ebx
lea    0xd3a(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xce9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13af <WrFileTest+0x1ef>
lea    0xd2a(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xcc3(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xc92(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     13af <WrFileTest+0x1ef>
mov    %rax,%rdi
call   1060 <fclose@plt>
lea    0x20(%rsp),%rdi
call   1040 <remove@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd12(%rip),%rdi
call   10c0 <WrMessage@plt>
movl   $0x0,(%r15)
lea    0x20(%rsp),%rdi
call   10d0 <tmpnam@plt>
test   %rax,%rax
je     1507 <WrFileTest+0x347>
movl   $0x0,(%r15)
lea    0xd00(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     14ad <WrFileTest+0x2ed>
mov    %rax,%rbx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
movl   $0x0,(%r15)
lea    0xbed(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     14d6 <WrFileTest+0x316>
mov    %rax,%rbx
movl   $0x0,(%r15)
mov    %rsp,%rdi
mov    $0x14,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    (%r15),%ebp
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    147f <WrFileTest+0x2bf>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     1515 <WrFileTest+0x355>
lea    0xc81(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xb9f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    14fd <WrFileTest+0x33d>
mov    (%r15),%ebx
lea    0xbbf(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb6e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1507 <WrFileTest+0x347>
mov    (%r15),%ebx
lea    0xc10(%rip),%rdi
call   10c0 <WrMessage@plt>
mov    %ebx,%edi
call   10e0 <strerror@plt>
lea    0xb45(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x20(%rsp),%rdi
call   1040 <remove@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbeb(%rip),%rdi
call   10c0 <WrMessage@plt>
jmp    14a3 <WrFileTest+0x2e3>

LLVM IR (-O0):
@.str = [15 x i8] c"@FILE-HANDLING\00"
@.str.1 = [17 x i8] c"@FILE-EMPTY-NAME\00"
@errno = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [22 x i8] c"@FILE-EMPTY-NAME-NULL\00"
@.str.5 = [18 x i8] c"System error: %s\0A\00"
@.str.6 = [25 x i8] c"@FILE-EMPTY-NAME-SUCCESS\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [17 x i8] c"@FILE-OPEN-TWICE\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [22 x i8] c"@FILE-OPEN-ONCE-ERROR\00"
@.str.11 = [23 x i8] c"@FILE-OPEN-TWICE-ERROR\00"
@.str.12 = [26 x i8] c"@FILE-OPEN-TWICE-NO-ERROR\00"
@.str.13 = [21 x i8] c"@FILE-TMP-NAME-ERROR\00"
@.str.14 = [27 x i8] c"@FILE-MIX-FORMATTED-BINARY\00"
@.str.15 = [3 x i8] c"wb\00"
@.str.16 = [23 x i8] c"@FILE-MIX-REOPEN-ERROR\00"
@.str.17 = [24 x i8] c"@FILE-MIX-READ-NO-ERROR\00"
define void @WrFileTest() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = call i32 @WrMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* @errno
%9 = call i32* @fopen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %1
%10 = load i32, i32* @errno
store i32 %10, i32* %6
%11 = load i32*, i32** %1
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = call i32 @WrMessage(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32, i32* %6
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %16)
br label %25
18: ; preds = %0
%19 = call i32 @WrMessage(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%20 = load i32, i32* %6
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %1
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %18, %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%27 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = call i8* @tmpnam(i8* %28)
store i8* %29, i8** %3
%30 = load i32, i32* @errno
store i32 %30, i32* %6
%31 = load i8*, i8** %3
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %76
33: ; preds = %25
store i32 0, i32* @errno
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %35, i32** %1
%36 = load i32, i32* @errno
store i32 %36, i32* %6
%37 = load i32*, i32** %1
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %33
%40 = call i32 @WrMessage(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%41 = load i32, i32* %6
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %42)
br label %75
44: ; preds = %33
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %46, i32** %2
%47 = load i32, i32* @errno
store i32 %47, i32* %6
%48 = load i32*, i32** %2
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %55
50: ; preds = %44
%51 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%52 = load i32, i32* %6
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %53)
br label %62
55: ; preds = %44
%56 = call i32 @WrMessage(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
%57 = load i32, i32* %6
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %58)
%60 = load i32*, i32** %2
%61 = call i32 @fclose(i32* %60)
br label %62
62: ; preds = %55, %50
%63 = load i32*, i32** %1
%64 = call i32 @fclose(i32* %63)
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %66, i32** %1
%67 = load i32*, i32** %1
%68 = icmp ne i32* %67, null
br i1 %68, label %69, label %74
69: ; preds = %62
%70 = load i32*, i32** %1
%71 = call i32 @fclose(i32* %70)
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%73 = call i32 @remove(i8* %72)
br label %74
74: ; preds = %69, %62
br label %75
75: ; preds = %74, %39
br label %83
76: ; preds = %25
%77 = call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
%78 = load i32, i32* %6
%79 = call i8* @strerror(i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %79)
%81 = load i32*, i32** %1
%82 = call i32 @fclose(i32* %81)
br label %83
83: ; preds = %76, %75
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%85 = call i32 @WrMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* @errno
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%87 = call i8* @tmpnam(i8* %86)
store i8* %87, i8** %3
%88 = load i32, i32* @errno
store i32 %88, i32* %6
%89 = load i8*, i8** %3
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %144
91: ; preds = %83
store i32 0, i32* @errno
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%93 = call i32* @fopen(i8* %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
store i32* %93, i32** %1
%94 = load i32, i32* @errno
store i32 %94, i32* %6
%95 = load i32*, i32** %1
%96 = icmp eq i32* %95, null
br i1 %96, label %97, label %102
97: ; preds = %91
%98 = call i32 @WrMessage(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%99 = load i32, i32* %6
%100 = call i8* @strerror(i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %100)
br label %143
102: ; preds = %91
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%104 = load i32*, i32** %1
%105 = call i32 @fwrite(i8* %103, i32 1, i32 256, i32* %104)
%106 = load i32*, i32** %1
%107 = call i32 @fclose(i32* %106)
store i32 0, i32* @errno
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%109 = call i32* @fopen(i8* %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %109, i32** %1
%110 = load i32, i32* @errno
store i32 %110, i32* %6
%111 = load i32*, i32** %1
%112 = icmp eq i32* %111, null
br i1 %112, label %113, label %118
113: ; preds = %102
%114 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.16, i64 0, i64 0))
%115 = load i32, i32* %6
%116 = call i8* @strerror(i32 %115)
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %116)
br label %140
118: ; preds = %102
store i32 0, i32* @errno
%119 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%120 = load i32*, i32** %1
%121 = call i32 @fgets(i8* %119, i32 20, i32* %120)
%122 = load i32, i32* @errno
store i32 %122, i32* %6
%123 = load i32*, i32** %1
%124 = call i64 @feof(i32* %123)
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %132
126: ; preds = %118
%127 = load i32*, i32** %1
%128 = call i64 @ferror(i32* %127)
%129 = icmp eq i64 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %126
%131 = call i32 @WrMessage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
br label %137
132: ; preds = %126, %118
%133 = call i32 @WrMessage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
%134 = load i32, i32* %6
%135 = call i8* @strerror(i32 %134)
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %135)
br label %137
137: ; preds = %132, %130
%138 = load i32*, i32** %1
%139 = call i32 @fclose(i32* %138)
br label %140
140: ; preds = %137, %113
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%142 = call i32 @remove(i8* %141)
br label %143
143: ; preds = %140, %97
br label %144
144: ; preds = %143, %83
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"@FILE-HANDLING\00"
@.str.1 = [17 x i8] c"@FILE-EMPTY-NAME\00"
@errno = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [22 x i8] c"@FILE-EMPTY-NAME-NULL\00"
@.str.5 = [18 x i8] c"System error: %s\0A\00"
@.str.6 = [25 x i8] c"@FILE-EMPTY-NAME-SUCCESS\00"
@.str.8 = [17 x i8] c"@FILE-OPEN-TWICE\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [22 x i8] c"@FILE-OPEN-ONCE-ERROR\00"
@.str.11 = [23 x i8] c"@FILE-OPEN-TWICE-ERROR\00"
@.str.12 = [26 x i8] c"@FILE-OPEN-TWICE-NO-ERROR\00"
@.str.13 = [21 x i8] c"@FILE-TMP-NAME-ERROR\00"
@.str.14 = [27 x i8] c"@FILE-MIX-FORMATTED-BINARY\00"
@.str.15 = [3 x i8] c"wb\00"
@.str.16 = [23 x i8] c"@FILE-MIX-REOPEN-ERROR\00"
@.str.17 = [24 x i8] c"@FILE-MIX-READ-NO-ERROR\00"
define void @WrFileTest() {
%1 = alloca [20 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @WrMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* @errno
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = load i32, i32* @errno
%9 = icmp eq i32* %7, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = tail call i32 @WrMessage(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i8* @strerror(i32 %8)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %12)
br label %19
14: ; preds = %0
%15 = tail call i32 @WrMessage(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%16 = tail call i8* @strerror(i32 %8)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%18 = tail call i32 @fclose(i32* %7)
br label %19
19: ; preds = %14, %10
%20 = tail call i32 @putchar(i32 10)
%21 = tail call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* @errno
%22 = call i8* @tmpnam(i8* %4)
%23 = icmp eq i8* %22, null
br i1 %23, label %52, label %24
24: ; preds = %19
store i32 0, i32* @errno
%25 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* @errno
%29 = call i32 @WrMessage(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%30 = call i8* @strerror(i32 %28)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %30)
br label %58
32: ; preds = %24
%33 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%34 = load i32, i32* @errno
%35 = icmp eq i32* %33, null
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
%38 = call i8* @strerror(i32 %34)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %38)
br label %45
40: ; preds = %32
%41 = call i32 @WrMessage(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
%42 = call i8* @strerror(i32 %34)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%44 = call i32 @fclose(i32* %33)
br label %45
45: ; preds = %40, %36
%46 = call i32 @fclose(i32* %25)
%47 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i32* %47, null
br i1 %48, label %58, label %49
49: ; preds = %45
%50 = call i32 @fclose(i32* %47)
%51 = call i32 @remove(i8* %4)
br label %58
52: ; preds = %19
%53 = load i32, i32* @errno
%54 = call i32 @WrMessage(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
%55 = call i8* @strerror(i32 %53)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %55)
%57 = call i32 @fclose(i32* %7)
br label %58
58: ; preds = %27, %49, %45, %52
%59 = call i32 @putchar(i32 10)
%60 = call i32 @WrMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* @errno
%61 = call i8* @tmpnam(i8* %4)
%62 = icmp eq i8* %61, null
br i1 %62, label %99, label %63
63: ; preds = %58
store i32 0, i32* @errno
%64 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
%65 = icmp eq i32* %64, null
br i1 %65, label %66, label %71
66: ; preds = %63
%67 = load i32, i32* @errno
%68 = call i32 @WrMessage(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%69 = call i8* @strerror(i32 %67)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %69)
br label %99
71: ; preds = %63
%72 = call i32 @fwrite(i8* %4, i32 1, i32 256, i32* %64)
%73 = call i32 @fclose(i32* %64)
store i32 0, i32* @errno
%74 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %81
76: ; preds = %71
%77 = load i32, i32* @errno
%78 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.16, i64 0, i64 0))
%79 = call i8* @strerror(i32 %77)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %79)
br label %97
81: ; preds = %71
store i32 0, i32* @errno
%82 = call i32 @fgets(i8* %3, i32 20, i32* %74)
%83 = load i32, i32* @errno
%84 = call i64 @feof(i32* %74)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %81
%87 = call i64 @ferror(i32* %74)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = call i32 @WrMessage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
br label %95
91: ; preds = %86, %81
%92 = call i32 @WrMessage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0))
%93 = call i8* @strerror(i32 %83)
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %93)
br label %95
95: ; preds = %91, %89
%96 = call i32 @fclose(i32* %74)
br label %97
97: ; preds = %95, %76
%98 = call i32 @remove(i8* %4)
br label %99
99: ; preds = %66, %97, %58
ret void
}