#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ENOSYS;
int EOF;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fmemopen(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int fstat(int, struct stat *);
scalar_t__ fwrite(char const *, int, scalar_t__, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
scalar_t__ mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
                int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char const *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  const char blah[] = "BLAH";
  FILE *fp;
  char *mmap_data;
  int ch, fd;
  struct stat fs;
  const char *cp;
  if ((fp = fopen("test-1", "w+")) == NULL)
    exit(1);
  if (fwrite(blah, 1, strlen(blah), fp) != strlen(blah))
    exit(2);
  rewind(fp);
  printf("file: ");
  cp = blah;
  while ((ch = getc(fp)) != EOF) {
    fputc(ch, stdout);
    if (ch != *cp) {
      printf("\ncharacter %td: '%c' instead of '%c'\n", cp - blah, ch, *cp);
      exit(1);
    }
    ++cp;
  }
  fputc('\n', stdout);
  if (ferror(fp)) {
    puts("fp: error");
    exit(1);
  }
  if (feof(fp))
    printf("fp: EOF\n");
  else {
    puts("not EOF");
    exit(1);
  }
  fclose(fp);
  if ((fd = open("test-1", O_RDONLY)) == -1)
    exit(3);
  if (fstat(fd, &fs) == -1)
    exit(4);
  if ((mmap_data = (char *)mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, fd,
                                0)) == MAP_FAILED) {
    if (errno == ENOSYS)
      exit(0);
    exit(5);
  }
  if ((fp = fmemopen(mmap_data, fs.st_size, "r")) == NULL)
    exit(1);
  printf("mem: ");
  cp = blah;
  while ((ch = getc(fp)) != EOF) {
    fputc(ch, stdout);
    if (ch != *cp) {
      printf("%td character: '%c' instead of '%c'\n", cp - blah, ch, *cp);
      exit(1);
    }
    ++cp;
  }
  fputc('\n', stdout);
  if (ferror(fp)) {
    puts("fp: error");
    exit(1);
  }
  if (feof(fp))
    printf("fp: EOF\n");
  else {
    puts("not EOF");
    exit(1);
  }
  fclose(fp);
  munmap(mmap_data, fs.st_size);
  unlink("test-1");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xdcb(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xdc6(%rip),%al
mov    %al,-0x5(%rbp)
lea    0xdbd(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    126c <main+0x4c>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x9(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1120 <fwrite@plt>
mov    %rax,-0x40(%rbp)
lea    -0x9(%rbp),%rdi
call   1080 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     12b9 <main+0x99>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <rewind@plt>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1140 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cdd(%rip),%rcx
cmp    (%rcx),%eax
je     1357 <main+0x137>
mov    -0x24(%rbp),%eax
mov    0x2cb3(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10c0 <fputc@plt>
mov    -0x24(%rbp),%eax
mov    -0x38(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1346 <main+0x126>
mov    -0x38(%rbp),%rsi
lea    -0x9(%rbp),%rax
sub    %rax,%rsi
mov    -0x24(%rbp),%edx
mov    -0x38(%rbp),%rax
movsbl (%rax),%ecx
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12d8 <main+0xb8>
mov    0x2c52(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   10c0 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ferror@plt>
cmp    $0x0,%rax
je     1393 <main+0x173>
lea    0xcb8(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <feof@plt>
cmp    $0x0,%rax
je     13b9 <main+0x199>
lea    0xc99(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    13cf <main+0x1af>
lea    0xc8f(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
mov    0x2bf9(%rip),%rax
mov    (%rax),%esi
lea    0xc1d(%rip),%rdi
call   10f0 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    1403 <main+0x1e3>
mov    $0x3,%edi
call   1110 <exit@plt>
mov    -0x28(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1130 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1422 <main+0x202>
mov    $0x4,%edi
call   1110 <exit@plt>
mov    -0x30(%rbp),%esi
mov    0x2bcc(%rip),%rax
mov    (%rax),%edx
mov    0x2bb3(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1090 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2b56(%rip),%rcx
cmp    (%rcx),%rax
jne    1486 <main+0x266>
mov    0x2b56(%rip),%rax
mov    (%rax),%rax
mov    0x2b64(%rip),%rcx
cmp    (%rcx),%rax
jne    147c <main+0x25c>
xor    %edi,%edi
call   1110 <exit@plt>
mov    $0x5,%edi
call   1110 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
lea    0xbb0(%rip),%rdx
call   1040 <fmemopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    14b1 <main+0x291>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xb9f(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1140 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2aee(%rip),%rcx
cmp    (%rcx),%eax
je     1546 <main+0x326>
mov    -0x24(%rbp),%eax
mov    0x2ac4(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10c0 <fputc@plt>
mov    -0x24(%rbp),%eax
mov    -0x38(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1535 <main+0x315>
mov    -0x38(%rbp),%rsi
lea    -0x9(%rbp),%rax
sub    %rax,%rsi
mov    -0x24(%rbp),%edx
mov    -0x38(%rbp),%rax
movsbl (%rax),%ecx
lea    0xb39(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    14c7 <main+0x2a7>
mov    0x2a63(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   10c0 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ferror@plt>
cmp    $0x0,%rax
je     1582 <main+0x362>
lea    0xac9(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <feof@plt>
cmp    $0x0,%rax
je     15a8 <main+0x388>
lea    0xaaa(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    15be <main+0x39e>
lea    0xaa0(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   10e0 <munmap@plt>
lea    0xa2b(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x48414c42,0x8(%rsp)
48
lea    0xdc3(%rip),%rdi
lea    0xdc3(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     14b1 <main+0x291>
mov    %rax,%r14
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1120 <fwrite@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1080 <strlen@plt>
cmp    %rax,%rbp
jne    14da <main+0x2ba>
mov    %r14,%rdi
call   10b0 <rewind@plt>
lea    0xd72(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14,%rdi
call   1140 <getc@plt>
mov    0x2d15(%rip),%r13
cmp    0x0(%r13),%eax
je     12fd <main+0xdd>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2cec(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%esi
movsbl %bpl,%edi
call   10c0 <fputc@plt>
movsbl 0x8(%rsp,%rbx,1),%ecx
cmp    %ecx,%ebp
jne    1490 <main+0x270>
mov    %r14,%rdi
call   1140 <getc@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    0x0(%r13),%eax
jne    12d0 <main+0xb0>
mov    0x2cac(%rip),%r15
mov    (%r15),%esi
mov    $0xa,%edi
call   10c0 <fputc@plt>
mov    %r14,%rdi
call   1060 <ferror@plt>
test   %rax,%rax
jne    14bb <main+0x29b>
mov    %r14,%rdi
call   10d0 <feof@plt>
test   %rax,%rax
je     14c4 <main+0x2a4>
lea    0xd3f(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
lea    0xcae(%rip),%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     14e4 <main+0x2c4>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1130 <fstat@plt>
cmp    $0xffffffff,%eax
je     14ee <main+0x2ce>
mov    0x10(%rsp),%ebp
mov    0x2c71(%rip),%rax
mov    (%rax),%edx
mov    0x2c58(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1090 <mmap@plt>
mov    %rax,%r14
mov    0x2bfd(%rip),%rax
cmp    %r14,(%rax)
je     14f8 <main+0x2d8>
lea    0xc89(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,0x14(%rsp)
mov    %ebp,%esi
call   1040 <fmemopen@plt>
test   %rax,%rax
je     14b1 <main+0x291>
mov    %rax,%r12
lea    0xc72(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r12,%rdi
call   1140 <getc@plt>
cmp    0x0(%r13),%eax
je     142c <main+0x20c>
mov    %eax,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%esi
movsbl %bl,%edi
call   10c0 <fputc@plt>
movsbl 0x8(%rsp,%rbp,1),%ecx
cmp    %ecx,%ebx
jne    149e <main+0x27e>
mov    %r12,%rdi
call   1140 <getc@plt>
mov    %eax,%ebx
add    $0x1,%rbp
cmp    0x0(%r13),%eax
jne    1400 <main+0x1e0>
mov    (%r15),%esi
mov    $0xa,%edi
call   10c0 <fputc@plt>
mov    %r12,%rdi
call   1060 <ferror@plt>
test   %rax,%rax
jne    14bb <main+0x29b>
mov    %r12,%rdi
call   10d0 <feof@plt>
test   %rax,%rax
je     14c4 <main+0x2a4>
lea    0xc1f(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
mov    0x14(%rsp),%esi
call   10e0 <munmap@plt>
lea    0xb8b(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb7f(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
jmp    14aa <main+0x28a>
lea    0xbaf(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xb7a(%rip),%rdi
jmp    14cb <main+0x2ab>
lea    0xb7b(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
mov    $0x4,%edi
call   1110 <exit@plt>
mov    0x2ab9(%rip),%rax
mov    (%rax),%rax
mov    0x2ac7(%rip),%rcx
cmp    (%rcx),%rax
jne    1515 <main+0x2f5>
xor    %edi,%edi
call   1110 <exit@plt>
mov    $0x5,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.main.blah = [5 x i8] c"BLAH\00"
@.str = [7 x i8] c"test-1\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [7 x i8] c"file: \00"
@EOF = global i32 0
@stdout = global i32 0
@.str.3 = [38 x i8] c"\0Acharacter %td: '%c' instead of '%c'\0A\00"
@.str.4 = [10 x i8] c"fp: error\00"
@.str.5 = [9 x i8] c"fp: EOF\0A\00"
@.str.6 = [8 x i8] c"not EOF\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@errno = global i64 0
@ENOSYS = global i64 0
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [6 x i8] c"mem: \00"
@.str.9 = [37 x i8] c"%td character: '%c' instead of '%c'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i8*
store i32 0, i32* %1
%9 = bitcast [5 x i8]* %2 to i8*
%10 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = load i32*, i32** %3
%19 = call i64 @fwrite(i8* %15, i32 1, i64 %17, i32* %18)
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = icmp ne i64 %19, %21
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %14
%26 = load i32*, i32** %3
%27 = call i32 @rewind(i32* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
store i8* %29, i8** %8
br label %30
30: ; preds = %57, %25
%31 = load i32*, i32** %3
%32 = call i32 @getc(i32* %31)
store i32 %32, i32* %5
%33 = load i32, i32* @EOF
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %60
35: ; preds = %30
%36 = load i32, i32* %5
%37 = trunc i32 %36 to i8
%38 = load i32, i32* @stdout
%39 = call i32 @fputc(i8 signext %37, i32 %38)
%40 = load i32, i32* %5
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %40, %43
br i1 %44, label %45, label %57
45: ; preds = %35
%46 = load i8*, i8** %8
%47 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = load i32, i32* %5
%52 = load i8*, i8** %8
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i64 %50, i32 %51, i32 %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %35
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %8
br label %30
60: ; preds = %30
%61 = load i32, i32* @stdout
%62 = call i32 @fputc(i8 signext 10, i32 %61)
%63 = load i32*, i32** %3
%64 = call i64 @ferror(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %60
%70 = load i32*, i32** %3
%71 = call i64 @feof(i32* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %78
75: ; preds = %69
%76 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %73
%79 = load i32*, i32** %3
%80 = call i32 @fclose(i32* %79)
%81 = load i32, i32* @O_RDONLY
%82 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %81)
store i32 %82, i32* %6
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %78
%85 = call i32 @exit(i32 3)
unreachable
86: ; preds = %78
%87 = load i32, i32* %6
%88 = call i32 @fstat(i32 %87, %struct.stat* %7)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %86
%91 = call i32 @exit(i32 4)
unreachable
92: ; preds = %86
%93 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%94 = load i32, i32* %93
%95 = load i32, i32* @PROT_READ
%96 = load i32, i32* @MAP_SHARED
%97 = load i32, i32* %6
%98 = call i64 @mmap(i32* null, i32 %94, i32 %95, i32 %96, i32 %97, i32 0)
%99 = inttoptr i64 %98 to i8*
store i8* %99, i8** %4
%100 = load i8*, i8** @MAP_FAILED
%101 = icmp eq i8* %99, %100
br i1 %101, label %102, label %110
102: ; preds = %92
%103 = load i64, i64* @errno
%104 = load i64, i64* @ENOSYS
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 @exit(i32 0)
unreachable
108: ; preds = %102
%109 = call i32 @exit(i32 5)
unreachable
110: ; preds = %92
%111 = load i8*, i8** %4
%112 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%113 = load i32, i32* %112
%114 = call i32* @fmemopen(i8* %111, i32 %113, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %114, i32** %3
%115 = icmp eq i32* %114, null
br i1 %115, label %116, label %118
116: ; preds = %110
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %110
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%120 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
store i8* %120, i8** %8
br label %121
121: ; preds = %148, %118
%122 = load i32*, i32** %3
%123 = call i32 @getc(i32* %122)
store i32 %123, i32* %5
%124 = load i32, i32* @EOF
%125 = icmp ne i32 %123, %124
br i1 %125, label %126, label %151
126: ; preds = %121
%127 = load i32, i32* %5
%128 = trunc i32 %127 to i8
%129 = load i32, i32* @stdout
%130 = call i32 @fputc(i8 signext %128, i32 %129)
%131 = load i32, i32* %5
%132 = load i8*, i8** %8
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = icmp ne i32 %131, %134
br i1 %135, label %136, label %148
136: ; preds = %126
%137 = load i8*, i8** %8
%138 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%139 = ptrtoint i8* %137 to i64
%140 = ptrtoint i8* %138 to i64
%141 = sub i64 %139, %140
%142 = load i32, i32* %5
%143 = load i8*, i8** %8
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i64 %141, i32 %142, i32 %145)
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %126
%149 = load i8*, i8** %8
%150 = getelementptr inbounds i8, i8* %149, i32 1
store i8* %150, i8** %8
br label %121
151: ; preds = %121
%152 = load i32, i32* @stdout
%153 = call i32 @fputc(i8 signext 10, i32 %152)
%154 = load i32*, i32** %3
%155 = call i64 @ferror(i32* %154)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %160
157: ; preds = %151
%158 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%159 = call i32 @exit(i32 1)
unreachable
160: ; preds = %151
%161 = load i32*, i32** %3
%162 = call i64 @feof(i32* %161)
%163 = icmp ne i64 %162, 0
br i1 %163, label %164, label %166
164: ; preds = %160
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %169
166: ; preds = %160
%167 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %164
%170 = load i32*, i32** %3
%171 = call i32 @fclose(i32* %170)
%172 = load i8*, i8** %4
%173 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%174 = load i32, i32* %173
%175 = call i32 @munmap(i8* %172, i32 %174)
%176 = call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.main.blah = [5 x i8] c"BLAH\00"
@.str = [7 x i8] c"test-1\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [7 x i8] c"file: \00"
@EOF = global i32 0
@stdout = global i32 0
@.str.3 = [38 x i8] c"\0Acharacter %td: '%c' instead of '%c'\0A\00"
@.str.4 = [10 x i8] c"fp: error\00"
@.str.6 = [8 x i8] c"not EOF\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@errno = global i64 0
@ENOSYS = global i64 0
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [6 x i8] c"mem: \00"
@.str.9 = [37 x i8] c"%td character: '%c' instead of '%c'\0A\00"
@str.10 = [8 x i8] c"fp: EOF\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.stat* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i64 @strlen(i8* %3)
%11 = call i64 @fwrite(i8* %3, i32 1, i64 %10, i32* %5)
%12 = call i64 @strlen(i8* %3)
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %9
%17 = tail call i32 @rewind(i32* %5)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @getc(i32* %5)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %43, label %22
22: ; preds = %16, %38
%23 = phi i32 [ %40, %38 ], [ %19, %16 ]
%24 = phi i8* [ %39, %38 ], [ %3, %16 ]
%25 = trunc i32 %23 to i8
%26 = load i32, i32* @stdout
%27 = tail call i32 @fputc(i8 signext %25, i32 %26)
%28 = load i8, i8* %24
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %23, %29
br i1 %30, label %38, label %31
31: ; preds = %22
%32 = sext i8 %28 to i32
%33 = ptrtoint i8* %24 to i64
%34 = ptrtoint [5 x i8]* %1 to i64
%35 = sub i64 %33, %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i64 %35, i32 %23, i32 %32)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %22
%39 = getelementptr inbounds i8, i8* %24, i64 1
%40 = tail call i32 @getc(i32* %5)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %22
43: ; preds = %38, %16
%44 = load i32, i32* @stdout
%45 = tail call i32 @fputc(i8 signext 10, i32 %44)
%46 = tail call i64 @ferror(i32* %5)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %43
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %43
%52 = tail call i64 @feof(i32* %5)
%53 = icmp eq i64 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %51
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%56 = tail call i32 @fclose(i32* %5)
%57 = load i32, i32* @O_RDONLY
%58 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %63, label %65
60: ; preds = %51
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%62 = tail call i32 @exit(i32 1)
unreachable
63: ; preds = %54
%64 = tail call i32 @exit(i32 3)
unreachable
65: ; preds = %54
%66 = call i32 @fstat(i32 %58, %struct.stat* %2)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = tail call i32 @exit(i32 4)
unreachable
70: ; preds = %65
%71 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%72 = load i32, i32* %71
%73 = load i32, i32* @PROT_READ
%74 = load i32, i32* @MAP_SHARED
%75 = tail call i64 @mmap(i32* null, i32 %72, i32 %73, i32 %74, i32 %58, i32 0)
%76 = inttoptr i64 %75 to i8*
%77 = load i8*, i8** @MAP_FAILED
%78 = icmp eq i8* %77, %76
br i1 %78, label %79, label %87
79: ; preds = %70
%80 = load i64, i64* @errno
%81 = load i64, i64* @ENOSYS
%82 = icmp eq i64 %80, %81
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = tail call i32 @exit(i32 0)
unreachable
85: ; preds = %79
%86 = tail call i32 @exit(i32 5)
unreachable
87: ; preds = %70
%88 = tail call i32* @fmemopen(i8* %76, i32 %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %92
90: ; preds = %87
%91 = tail call i32 @exit(i32 1)
unreachable
92: ; preds = %87
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%94 = tail call i32 @getc(i32* %88)
%95 = load i32, i32* @EOF
%96 = icmp eq i32 %94, %95
br i1 %96, label %118, label %97
97: ; preds = %92, %113
%98 = phi i32 [ %115, %113 ], [ %94, %92 ]
%99 = phi i8* [ %114, %113 ], [ %3, %92 ]
%100 = trunc i32 %98 to i8
%101 = load i32, i32* @stdout
%102 = tail call i32 @fputc(i8 signext %100, i32 %101)
%103 = load i8, i8* %99
%104 = sext i8 %103 to i32
%105 = icmp eq i32 %98, %104
br i1 %105, label %113, label %106
106: ; preds = %97
%107 = sext i8 %103 to i32
%108 = ptrtoint i8* %99 to i64
%109 = ptrtoint [5 x i8]* %1 to i64
%110 = sub i64 %108, %109
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i64 %110, i32 %98, i32 %107)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %97
%114 = getelementptr inbounds i8, i8* %99, i64 1
%115 = tail call i32 @getc(i32* %88)
%116 = load i32, i32* @EOF
%117 = icmp eq i32 %115, %116
br i1 %117, label %118, label %97
118: ; preds = %113, %92
%119 = load i32, i32* @stdout
%120 = tail call i32 @fputc(i8 signext 10, i32 %119)
%121 = tail call i64 @ferror(i32* %88)
%122 = icmp eq i64 %121, 0
br i1 %122, label %126, label %123
123: ; preds = %118
%124 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%125 = tail call i32 @exit(i32 1)
unreachable
126: ; preds = %118
%127 = tail call i64 @feof(i32* %88)
%128 = icmp eq i64 %127, 0
br i1 %128, label %134, label %129
129: ; preds = %126
%130 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%131 = tail call i32 @fclose(i32* %88)
%132 = tail call i32 @munmap(i8* %76, i32 %72)
%133 = tail call i32 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 0
134: ; preds = %126
%135 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%136 = tail call i32 @exit(i32 1)
unreachable
}