#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__ asprintf(char **, char *, char *);
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 /*<<< orphan*/ free(char *);
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(int argc, char **argv) {
  char *test_file;
  const char blah[] = "BLAH";
  FILE *fp;
  char *mmap_data;
  int ch, fd;
  struct stat fs;
  const char *cp;
  if (argc != 1 || asprintf(&test_file, "%s.test", argv[0]) < 0)
    exit(99);
  if ((fp = fopen(test_file, "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_file, 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_file);
  free(test_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xda4(%rip),%eax
mov    %eax,-0x1d(%rbp)
mov    0xd9f(%rip),%al
mov    %al,-0x19(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1293 <main+0x53>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    -0x18(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   10f0 <asprintf@plt>
cmp    $0x0,%rax
jge    129d <main+0x5d>
mov    $0x63,%edi
call   1130 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xd65(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12c5 <main+0x85>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0x1d(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x1d(%rbp),%rdi
call   1090 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1140 <fwrite@plt>
mov    %rax,-0x50(%rbp)
lea    -0x1d(%rbp),%rdi
call   1090 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
je     1312 <main+0xd2>
mov    $0x2,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <rewind@plt>
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
lea    -0x1d(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1160 <getc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2c84(%rip),%rcx
cmp    (%rcx),%eax
je     13b0 <main+0x170>
mov    -0x34(%rbp),%eax
mov    0x2c5a(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10d0 <fputc@plt>
mov    -0x34(%rbp),%eax
mov    -0x48(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     139f <main+0x15f>
mov    -0x48(%rbp),%rsi
lea    -0x1d(%rbp),%rax
sub    %rax,%rsi
mov    -0x34(%rbp),%edx
mov    -0x48(%rbp),%rax
movsbl (%rax),%ecx
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1331 <main+0xf1>
mov    0x2bf9(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   10d0 <fputc@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ferror@plt>
cmp    $0x0,%rax
je     13ec <main+0x1ac>
lea    0xc60(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
call   10e0 <feof@plt>
cmp    $0x0,%rax
je     1412 <main+0x1d2>
lea    0xc41(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
jmp    1428 <main+0x1e8>
lea    0xc37(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x18(%rbp),%rdi
mov    0x2b9c(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    1459 <main+0x219>
mov    $0x3,%edi
call   1130 <exit@plt>
mov    -0x38(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1150 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1478 <main+0x238>
mov    $0x4,%edi
call   1130 <exit@plt>
mov    -0x40(%rbp),%esi
mov    0x2b76(%rip),%rax
mov    (%rax),%edx
mov    0x2b5d(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   10a0 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    0x2b00(%rip),%rcx
cmp    (%rcx),%rax
jne    14dc <main+0x29c>
mov    0x2b00(%rip),%rax
mov    (%rax),%rax
mov    0x2b0e(%rip),%rcx
cmp    (%rcx),%rax
jne    14d2 <main+0x292>
xor    %edi,%edi
call   1130 <exit@plt>
mov    $0x5,%edi
call   1130 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%esi
lea    0xb5b(%rip),%rdx
call   1050 <fmemopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1507 <main+0x2c7>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xb4a(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
lea    -0x1d(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1160 <getc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2a98(%rip),%rcx
cmp    (%rcx),%eax
je     159c <main+0x35c>
mov    -0x34(%rbp),%eax
mov    0x2a6e(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10d0 <fputc@plt>
mov    -0x34(%rbp),%eax
mov    -0x48(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     158b <main+0x34b>
mov    -0x48(%rbp),%rsi
lea    -0x1d(%rbp),%rax
sub    %rax,%rsi
mov    -0x34(%rbp),%edx
mov    -0x48(%rbp),%rax
movsbl (%rax),%ecx
lea    0xae4(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    151d <main+0x2dd>
mov    0x2a0d(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   10d0 <fputc@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ferror@plt>
cmp    $0x0,%rax
je     15d8 <main+0x398>
lea    0xa74(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
call   10e0 <feof@plt>
cmp    $0x0,%rax
je     15fe <main+0x3be>
lea    0xa55(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
jmp    1614 <main+0x3d4>
lea    0xa4b(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%esi
call   1100 <munmap@plt>
mov    -0x18(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%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,0x4(%rsp)
movl   $0x48414c42,(%rsp)
cmp    $0x1,%edi
jne    150a <main+0x2ca>
mov    (%rsi),%rdx
lea    0xd98(%rip),%rsi
lea    0x8(%rsp),%rdi
call   10f0 <asprintf@plt>
test   %rax,%rax
js     150a <main+0x2ca>
mov    0x8(%rsp),%rdi
lea    0xd81(%rip),%rsi
call   1120 <fopen@plt>
test   %rax,%rax
je     1514 <main+0x2d4>
mov    %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1140 <fwrite@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1090 <strlen@plt>
cmp    %rax,%rbp
jne    153d <main+0x2fd>
mov    %r14,%rdi
call   10c0 <rewind@plt>
lea    0xd32(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r14,%rdi
call   1160 <getc@plt>
mov    0x2cd4(%rip),%r13
cmp    0x0(%r13),%eax
je     133c <main+0xfc>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2cab(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%esi
movsbl %bpl,%edi
call   10d0 <fputc@plt>
movsbl (%rsp,%rbx,1),%ecx
cmp    %ecx,%ebp
jne    14df <main+0x29f>
mov    %r14,%rdi
call   1160 <getc@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    0x0(%r13),%eax
jne    1310 <main+0xd0>
mov    0x2c6d(%rip),%r15
mov    (%r15),%esi
mov    $0xa,%edi
call   10d0 <fputc@plt>
mov    %r14,%rdi
call   1070 <ferror@plt>
test   %rax,%rax
jne    151e <main+0x2de>
mov    %r14,%rdi
call   10e0 <feof@plt>
test   %rax,%rax
je     1527 <main+0x2e7>
lea    0xd01(%rip),%rdi
call   1060 <puts@plt>
mov    %r14,%rdi
call   1080 <fclose@plt>
mov    0x8(%rsp),%rdi
mov    0x2c46(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     1547 <main+0x307>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1150 <fstat@plt>
cmp    $0xffffffff,%eax
je     1551 <main+0x311>
mov    0x10(%rsp),%ebp
mov    0x2c34(%rip),%rax
mov    (%rax),%edx
mov    0x2c1b(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   10a0 <mmap@plt>
mov    %rax,%r14
mov    0x2bc0(%rip),%rax
cmp    %r14,(%rax)
je     155b <main+0x31b>
lea    0xc4d(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,0x14(%rsp)
mov    %ebp,%esi
call   1050 <fmemopen@plt>
test   %rax,%rax
je     1514 <main+0x2d4>
mov    %rax,%r12
lea    0xc36(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r12,%rdi
call   1160 <getc@plt>
cmp    0x0(%r13),%eax
je     146b <main+0x22b>
mov    %eax,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%esi
movsbl %bl,%edi
call   10d0 <fputc@plt>
movsbl (%rsp,%rbp,1),%ecx
cmp    %ecx,%ebx
jne    14ed <main+0x2ad>
mov    %r12,%rdi
call   1160 <getc@plt>
mov    %eax,%ebx
add    $0x1,%rbp
cmp    0x0(%r13),%eax
jne    1440 <main+0x200>
mov    (%r15),%esi
mov    $0xa,%edi
call   10d0 <fputc@plt>
mov    %r12,%rdi
call   1070 <ferror@plt>
test   %rax,%rax
jne    151e <main+0x2de>
mov    %r12,%rdi
call   10e0 <feof@plt>
test   %rax,%rax
je     1527 <main+0x2e7>
lea    0xbd9(%rip),%rdi
call   1060 <puts@plt>
mov    %r12,%rdi
call   1080 <fclose@plt>
mov    %r14,%rdi
mov    0x14(%rsp),%esi
call   1100 <munmap@plt>
mov    0x8(%rsp),%rdi
call   1040 <unlink@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb31(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
jmp    14f9 <main+0x2b9>
lea    0xb61(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10b0 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    $0x63,%edi
call   1130 <exit@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xb18(%rip),%rdi
jmp    152e <main+0x2ee>
lea    0xb19(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    $0x2,%edi
call   1130 <exit@plt>
mov    $0x3,%edi
call   1130 <exit@plt>
mov    $0x4,%edi
call   1130 <exit@plt>
mov    0x2a56(%rip),%rax
mov    (%rax),%rax
mov    0x2a64(%rip),%rcx
cmp    (%rcx),%rax
jne    1578 <main+0x338>
xor    %edi,%edi
call   1130 <exit@plt>
mov    $0x5,%edi
call   1130 <exit@plt>

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

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