#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 */

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ O_WRONLY;
int PROT_READ;
int PROT_WRITE;
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int lseek(int, int, int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
main() {
  int fd, r, w, l;
  char buf[1024];
  char *v;
  fd = open("/dev/zero", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Unable to open /dev/zero for reading\n");
    perror("The error was");
    exit(1);
  }
  l = read(fd, buf, 1024);
  if (l != 1024) {
    fprintf(stderr, "Asked to read 1024 bytes, got %d\n", l);
    exit(1);
  }
  for (r = 0; r < 1024; r++)
    if (buf[r] != 0) {
      fprintf(stderr, "/dev/zero returned a byte of %02x at offset %d\n",
              buf[r], r);
      exit(1);
    }
  l = lseek(fd, 4096, 0);
  if (l != 0) {
    fprintf(stderr, "l == %d\n", l);
    exit(1);
  }
  l = close(fd);
  if (l != 0) {
    fprintf(stderr, "close: returned %d\n", l);
    perror("The error was");
    exit(1);
  }
  fd = open("/dev/zero", O_WRONLY);
  if (fd < 0) {
    fprintf(stderr, "Unable to open /dev/zero for writing\n");
    perror("The error was");
    exit(1);
  }
  l = write(fd, buf, 1024);
  if (l != 1024) {
    fprintf(stderr, "Asked to write 1024 bytes, got %d\n", l);
    exit(1);
  }
  l = close(fd);
  if (l != 0) {
    fprintf(stderr, "close: returned %d\n", l);
    perror("The error was");
    exit(1);
  }
  fd = open("/dev/zero", O_RDWR);
  v = (char *)mmap(0, 65536, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  if (v == (char *)-1) {
    fprintf(stderr, "mmap r/w /dev/zero failed\n");
    perror("The error was");
    exit(1);
  }
  for (r = 0; r < 65536; r++)
    if (v[r] != 0) {
      fprintf(stderr, "mmap'd r/w /dev/zero has byte %d at offset %d\n", v[r],
              r);
      exit(1);
    }
  munmap(v, 65536);
  close(fd);
  fd = open("/dev/zero", O_RDONLY);
  v = (char *)mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);
  if (v == (char *)-1) {
    fprintf(stderr, "mmap /dev/zero r/o failed\n");
    perror("The error was");
    exit(1);
  }
  for (r = 0; r < 65536; r++)
    if (v[r] != 0) {
      fprintf(stderr, "mmap'd r/o /dev/zero has byte %d at offset %d\n", v[r],
              r);
      exit(1);
    }
  munmap(v, 65536);
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1201 <main+0x61>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xe3e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
je     1249 <main+0xa9>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x400,-0xc(%rbp)
jge    12b5 <main+0x115>
movslq -0xc(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     12a2 <main+0x102>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
movslq -0xc(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edx
ff
mov    -0xc(%rbp),%ecx
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12a7 <main+0x107>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1250 <main+0xb0>
mov    -0x8(%rbp),%edi
mov    $0x1000,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12f5 <main+0x155>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     133a <main+0x19a>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd05(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c5f(%rip),%rax
mov    (%rax),%esi
lea    0xcb6(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1389 <main+0x1e9>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xcb6(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
je     13d1 <main+0x231>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1416 <main+0x276>
mov    0x2bd3(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xca0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xc29(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2bbb(%rip),%rax
mov    (%rax),%esi
lea    0xbda(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2bc3(%rip),%rax
mov    (%rax),%edx
mov    0x2b7a(%rip),%rax
or     (%rax),%edx
mov    0x2b69(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x428(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x428(%rbp)
jne    14a5 <main+0x305>
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
lea    0xc6e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xb9a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x10000,-0xc(%rbp)
jge    1517 <main+0x377>
mov    -0x428(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1504 <main+0x364>
mov    0x2ae8(%rip),%rax
mov    (%rax),%edi
mov    -0x428(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0xc(%rbp),%ecx
lea    0xc1e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1509 <main+0x369>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    14ac <main+0x30c>
mov    -0x428(%rbp),%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2a99(%rip),%rax
mov    (%rax),%esi
lea    0xac0(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2aa9(%rip),%rax
mov    (%rax),%edx
mov    0x2a90(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10000,%esi
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x428(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x428(%rbp)
jne    15b6 <main+0x416>
mov    0x2a30(%rip),%rax
mov    (%rax),%edi
lea    0xba7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xa89(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x10000,-0xc(%rbp)
jge    1628 <main+0x488>
mov    -0x428(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1615 <main+0x475>
mov    0x29d7(%rip),%rax
mov    (%rax),%edi
mov    -0x428(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0xc(%rbp),%ecx
lea    0xb57(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    161a <main+0x47a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    15bd <main+0x41d>
mov    -0x428(%rbp),%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2e1d(%rip),%r14
mov    (%r14),%esi
lea    0xe43(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
jns    11f3 <main+0x53>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xe4c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0x400,%eax
jne    12b3 <main+0x113>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rcx,1),%eax
test   %al,%al
jne    12e6 <main+0x146>
movzbl 0x1(%rsp,%rcx,1),%eax
test   %al,%al
jne    12d6 <main+0x136>
movzbl 0x2(%rsp,%rcx,1),%eax
test   %al,%al
jne    12dc <main+0x13c>
movzbl 0x3(%rsp,%rcx,1),%eax
test   %al,%al
jne    12e2 <main+0x142>
add    $0x4,%rcx
cmp    $0x400,%rcx
jne    1220 <main+0x80>
mov    %ebx,%edi
mov    $0x1000,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %eax,%eax
jne    130a <main+0x16a>
mov    %ebx,%edi
call   1060 <close@plt>
test   %eax,%eax
jne    13a3 <main+0x203>
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    0xd6b(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
jns    131c <main+0x17c>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
jmp    11d6 <main+0x36>
mov    0x2d06(%rip),%rcx
mov    (%rcx),%edi
lea    0xd7b(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
add    $0x1,%rcx
jmp    12e6 <main+0x146>
add    $0x2,%rcx
jmp    12e6 <main+0x146>
add    $0x3,%rcx
movsbl %al,%edx
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2caf(%rip),%rcx
mov    (%rcx),%edi
lea    0xd76(%rip),%rsi
jmp    12c3 <main+0x123>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1030 <write@plt>
cmp    $0x400,%eax
jne    13c1 <main+0x221>
mov    %ebx,%edi
call   1060 <close@plt>
test   %eax,%eax
jne    13a3 <main+0x203>
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
lea    0xcad(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
mov    0x2c97(%rip),%r15
mov    0x2c50(%rip),%rax
mov    (%rax),%edx
or     (%r15),%edx
mov    0x2c3c(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x10000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
jne    13d6 <main+0x236>
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
jmp    11d6 <main+0x36>
mov    0x2c16(%rip),%rcx
mov    (%rcx),%edi
lea    0xce6(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    11dd <main+0x3d>
mov    0x2bf8(%rip),%rcx
mov    (%rcx),%edi
lea    0xd02(%rip),%rsi
jmp    12c3 <main+0x123>
mov    $0x3,%ecx
nopl   0x0(%rax,%rax,1)
movzbl -0x3(%rax,%rcx,1),%edx
test   %dl,%dl
jne    1476 <main+0x2d6>
movzbl -0x2(%rax,%rcx,1),%edx
test   %dl,%dl
jne    147c <main+0x2dc>
movzbl -0x1(%rax,%rcx,1),%edx
test   %dl,%dl
jne    1482 <main+0x2e2>
movzbl (%rax,%rcx,1),%edx
test   %dl,%dl
jne    1486 <main+0x2e6>
add    $0x4,%rcx
cmp    $0x10003,%rcx
jne    13e0 <main+0x240>
mov    %rax,%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    (%r14),%esi
lea    0xbca(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
mov    (%r15),%edx
mov    0x2ba1(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x10000,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
jne    149e <main+0x2fe>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
lea    0xccf(%rip),%rsi
jmp    11d6 <main+0x36>
add    $0xfffffffffffffffd,%rcx
jmp    1486 <main+0x2e6>
add    $0xfffffffffffffffe,%rcx
jmp    1486 <main+0x2e6>
add    $0xffffffffffffffff,%rcx
movsbl %dl,%edx
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
lea    0xc78(%rip),%rsi
jmp    12f9 <main+0x159>
mov    $0x3,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl -0x3(%rax,%rcx,1),%edx
test   %dl,%dl
jne    14fb <main+0x35b>
movzbl -0x2(%rax,%rcx,1),%edx
test   %dl,%dl
jne    1501 <main+0x361>
movzbl -0x1(%rax,%rcx,1),%edx
test   %dl,%dl
jne    1507 <main+0x367>
movzbl (%rax,%rcx,1),%edx
test   %dl,%dl
jne    150b <main+0x36b>
add    $0x4,%rcx
cmp    $0x10003,%rcx
jne    14b0 <main+0x310>
mov    %rax,%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
add    $0xfffffffffffffffd,%rcx
jmp    150b <main+0x36b>
add    $0xfffffffffffffffe,%rcx
jmp    150b <main+0x36b>
add    $0xffffffffffffffff,%rcx
movsbl %dl,%edx
mov    0x2aab(%rip),%rax
mov    (%rax),%edi
lea    0xc3d(%rip),%rsi
jmp    12f9 <main+0x159>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [38 x i8] c"Unable to open /dev/zero for reading\0A\00"
@.str.2 = [14 x i8] c"The error was\00"
@.str.3 = [34 x i8] c"Asked to read 1024 bytes, got %d\0A\00"
@.str.4 = [48 x i8] c"/dev/zero returned a byte of %02x at offset %d\0A\00"
@.str.5 = [9 x i8] c"l == %d\0A\00"
@.str.6 = [20 x i8] c"close: returned %d\0A\00"
@O_WRONLY = global i32 0
@.str.7 = [38 x i8] c"Unable to open /dev/zero for writing\0A\00"
@.str.8 = [35 x i8] c"Asked to write 1024 bytes, got %d\0A\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.9 = [27 x i8] c"mmap r/w /dev/zero failed\0A\00"
@.str.10 = [47 x i8] c"mmap'd r/w /dev/zero has byte %d at offset %d\0A\00"
@MAP_SHARED = global i32 0
@.str.11 = [27 x i8] c"mmap /dev/zero r/o failed\0A\00"
@.str.12 = [47 x i8] c"mmap'd r/o /dev/zero has byte %d at offset %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i8*
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* %2
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 1024)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 1024
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i32, i32* %5
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %17
store i32 0, i32* %3
br label %29
29: ; preds = %50, %28
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 1024
br i1 %31, label %32, label %53
32: ; preds = %29
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = load i32, i32* %3
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %32
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %29
53: ; preds = %29
%54 = load i32, i32* %2
%55 = call i32 @lseek(i32 %54, i32 4096, i32 0)
store i32 %55, i32* %5
%56 = load i32, i32* %5
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i32, i32* %5
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %53
%64 = load i32, i32* %2
%65 = call i32 @close(i32 %64)
store i32 %65, i32* %5
%66 = load i32, i32* %5
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = load i32, i32* %5
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %63
%75 = load i32, i32* @O_WRONLY
%76 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %75)
store i32 %76, i32* %2
%77 = load i32, i32* %2
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%82 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %74
%85 = load i32, i32* %2
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%87 = call i32 @write(i32 %85, i8* %86, i32 1024)
store i32 %87, i32* %5
%88 = load i32, i32* %5
%89 = icmp ne i32 %88, 1024
br i1 %89, label %90, label %95
90: ; preds = %84
%91 = load i32, i32* @stderr
%92 = load i32, i32* %5
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 %92)
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %84
%96 = load i32, i32* %2
%97 = call i32 @close(i32 %96)
store i32 %97, i32* %5
%98 = load i32, i32* %5
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %106
100: ; preds = %95
%101 = load i32, i32* @stderr
%102 = load i32, i32* %5
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %102)
%104 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %95
%107 = load i32, i32* @O_RDWR
%108 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %107)
store i32 %108, i32* %2
%109 = load i32, i32* @PROT_READ
%110 = load i32, i32* @PROT_WRITE
%111 = or i32 %109, %110
%112 = load i32, i32* @MAP_PRIVATE
%113 = load i32, i32* %2
%114 = call i64 @mmap(i32 0, i32 65536, i32 %111, i32 %112, i32 %113, i32 0)
%115 = inttoptr i64 %114 to i8*
store i8* %115, i8** %7
%116 = load i8*, i8** %7
%117 = icmp eq i8* %116, inttoptr (i64 -1 to i8*)
br i1 %117, label %118, label %123
118: ; preds = %106
%119 = load i32, i32* @stderr
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%121 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%122 = call i32 @exit(i32 1)
unreachable
123: ; preds = %106
store i32 0, i32* %3
br label %124
124: ; preds = %147, %123
%125 = load i32, i32* %3
%126 = icmp slt i32 %125, 65536
br i1 %126, label %127, label %150
127: ; preds = %124
%128 = load i8*, i8** %7
%129 = load i32, i32* %3
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %128, i64 %130
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %146
135: ; preds = %127
%136 = load i32, i32* @stderr
%137 = load i8*, i8** %7
%138 = load i32, i32* %3
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds i8, i8* %137, i64 %139
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
%143 = load i32, i32* %3
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %142, i32 %143)
%145 = call i32 @exit(i32 1)
unreachable
146: ; preds = %127
br label %147
147: ; preds = %146
%148 = load i32, i32* %3
%149 = add nsw i32 %148, 1
store i32 %149, i32* %3
br label %124
150: ; preds = %124
%151 = load i8*, i8** %7
%152 = call i32 @munmap(i8* %151, i32 65536)
%153 = load i32, i32* %2
%154 = call i32 @close(i32 %153)
%155 = load i32, i32* @O_RDONLY
%156 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %155)
store i32 %156, i32* %2
%157 = load i32, i32* @PROT_READ
%158 = load i32, i32* @MAP_SHARED
%159 = load i32, i32* %2
%160 = call i64 @mmap(i32 0, i32 65536, i32 %157, i32 %158, i32 %159, i32 0)
%161 = inttoptr i64 %160 to i8*
store i8* %161, i8** %7
%162 = load i8*, i8** %7
%163 = icmp eq i8* %162, inttoptr (i64 -1 to i8*)
br i1 %163, label %164, label %169
164: ; preds = %150
%165 = load i32, i32* @stderr
%166 = call i32 (i32, i8*, ...) @fprintf(i32 %165, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%167 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %150
store i32 0, i32* %3
br label %170
170: ; preds = %193, %169
%171 = load i32, i32* %3
%172 = icmp slt i32 %171, 65536
br i1 %172, label %173, label %196
173: ; preds = %170
%174 = load i8*, i8** %7
%175 = load i32, i32* %3
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i8, i8* %174, i64 %176
%178 = load i8, i8* %177
%179 = sext i8 %178 to i32
%180 = icmp ne i32 %179, 0
br i1 %180, label %181, label %192
181: ; preds = %173
%182 = load i32, i32* @stderr
%183 = load i8*, i8** %7
%184 = load i32, i32* %3
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds i8, i8* %183, i64 %185
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = load i32, i32* %3
%190 = call i32 (i32, i8*, ...) @fprintf(i32 %182, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 %188, i32 %189)
%191 = call i32 @exit(i32 1)
unreachable
192: ; preds = %173
br label %193
193: ; preds = %192
%194 = load i32, i32* %3
%195 = add nsw i32 %194, 1
store i32 %195, i32* %3
br label %170
196: ; preds = %170
%197 = load i8*, i8** %7
%198 = call i32 @munmap(i8* %197, i32 65536)
%199 = load i32, i32* %2
%200 = call i32 @close(i32 %199)
%201 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [38 x i8] c"Unable to open /dev/zero for reading\0A\00"
@.str.2 = [14 x i8] c"The error was\00"
@.str.3 = [34 x i8] c"Asked to read 1024 bytes, got %d\0A\00"
@.str.4 = [48 x i8] c"/dev/zero returned a byte of %02x at offset %d\0A\00"
@.str.5 = [9 x i8] c"l == %d\0A\00"
@.str.6 = [20 x i8] c"close: returned %d\0A\00"
@O_WRONLY = global i32 0
@.str.7 = [38 x i8] c"Unable to open /dev/zero for writing\0A\00"
@.str.8 = [35 x i8] c"Asked to write 1024 bytes, got %d\0A\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.9 = [27 x i8] c"mmap r/w /dev/zero failed\0A\00"
@.str.10 = [47 x i8] c"mmap'd r/w /dev/zero has byte %d at offset %d\0A\00"
@MAP_SHARED = global i32 0
@.str.11 = [27 x i8] c"mmap /dev/zero r/o failed\0A\00"
@.str.12 = [47 x i8] c"mmap'd r/o /dev/zero has byte %d at offset %d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @read(i32 %4, i8* %2, i32 1024)
%13 = icmp eq i32 %12, 1024
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %46
%19 = phi i64 [ %47, %46 ], [ 0, %11 ]
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %41, %36, %31, %18
%24 = phi i64 [ %19, %18 ], [ %32, %31 ], [ %37, %36 ], [ %42, %41 ]
%25 = phi i8 [ %21, %18 ], [ %34, %31 ], [ %39, %36 ], [ %44, %41 ]
%26 = trunc i64 %24 to i32
%27 = sext i8 %25 to i32
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %26)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%32 = or i64 %19, 1
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %23
36: ; preds = %31
%37 = or i64 %19, 2
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 0
br i1 %40, label %41, label %23
41: ; preds = %36
%42 = or i64 %19, 3
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 0
br i1 %45, label %46, label %23
46: ; preds = %41
%47 = add nuw nsw i64 %19, 4
%48 = icmp eq i64 %47, 1024
br i1 %48, label %49, label %18
49: ; preds = %46
%50 = tail call i32 @lseek(i32 %4, i32 4096, i32 0)
%51 = icmp eq i32 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %49
%57 = tail call i32 @close(i32 %4)
%58 = icmp eq i32 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = tail call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%62 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%63 = tail call i32 @exit(i32 1)
unreachable
64: ; preds = %56
%65 = load i32, i32* @O_WRONLY
%66 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%71 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%72 = tail call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = call i32 @write(i32 %66, i8* %2, i32 1024)
%75 = icmp eq i32 %74, 1024
br i1 %75, label %80, label %76
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = tail call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 %74)
%79 = tail call i32 @exit(i32 1)
unreachable
80: ; preds = %73
%81 = tail call i32 @close(i32 %66)
%82 = icmp eq i32 %81, 0
br i1 %82, label %88, label %83
83: ; preds = %80
%84 = load i32, i32* @stderr
%85 = tail call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %81)
%86 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%87 = tail call i32 @exit(i32 1)
unreachable
88: ; preds = %80
%89 = load i32, i32* @O_RDWR
%90 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %89)
%91 = load i32, i32* @PROT_READ
%92 = load i32, i32* @PROT_WRITE
%93 = or i32 %92, %91
%94 = load i32, i32* @MAP_PRIVATE
%95 = tail call i64 @mmap(i32 0, i32 65536, i32 %93, i32 %94, i32 %90, i32 0)
%96 = inttoptr i64 %95 to i8*
%97 = icmp eq i8* %96, inttoptr (i64 -1 to i8*)
br i1 %97, label %98, label %103
98: ; preds = %88
%99 = load i32, i32* @stderr
%100 = tail call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%101 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%102 = tail call i32 @exit(i32 1)
unreachable
103: ; preds = %88, %131
%104 = phi i64 [ %132, %131 ], [ 0, %88 ]
%105 = getelementptr inbounds i8, i8* %96, i64 %104
%106 = load i8, i8* %105
%107 = icmp eq i8 %106, 0
br i1 %107, label %116, label %108
108: ; preds = %126, %121, %116, %103
%109 = phi i64 [ %104, %103 ], [ %117, %116 ], [ %122, %121 ], [ %127, %126 ]
%110 = phi i8 [ %106, %103 ], [ %119, %116 ], [ %124, %121 ], [ %129, %126 ]
%111 = trunc i64 %109 to i32
%112 = sext i8 %110 to i32
%113 = load i32, i32* @stderr
%114 = tail call i32 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %112, i32 %111)
%115 = tail call i32 @exit(i32 1)
unreachable
116: ; preds = %103
%117 = or i64 %104, 1
%118 = getelementptr inbounds i8, i8* %96, i64 %117
%119 = load i8, i8* %118
%120 = icmp eq i8 %119, 0
br i1 %120, label %121, label %108
121: ; preds = %116
%122 = or i64 %104, 2
%123 = getelementptr inbounds i8, i8* %96, i64 %122
%124 = load i8, i8* %123
%125 = icmp eq i8 %124, 0
br i1 %125, label %126, label %108
126: ; preds = %121
%127 = or i64 %104, 3
%128 = getelementptr inbounds i8, i8* %96, i64 %127
%129 = load i8, i8* %128
%130 = icmp eq i8 %129, 0
br i1 %130, label %131, label %108
131: ; preds = %126
%132 = add nuw nsw i64 %104, 4
%133 = icmp eq i64 %132, 65536
br i1 %133, label %134, label %103
134: ; preds = %131
%135 = tail call i32 @munmap(i8* %96, i32 65536)
%136 = tail call i32 @close(i32 %90)
%137 = load i32, i32* @O_RDONLY
%138 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %137)
%139 = load i32, i32* @PROT_READ
%140 = load i32, i32* @MAP_SHARED
%141 = tail call i64 @mmap(i32 0, i32 65536, i32 %139, i32 %140, i32 %138, i32 0)
%142 = inttoptr i64 %141 to i8*
%143 = icmp eq i8* %142, inttoptr (i64 -1 to i8*)
br i1 %143, label %144, label %149
144: ; preds = %134
%145 = load i32, i32* @stderr
%146 = tail call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%147 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%148 = tail call i32 @exit(i32 1)
unreachable
149: ; preds = %134, %177
%150 = phi i64 [ %178, %177 ], [ 0, %134 ]
%151 = getelementptr inbounds i8, i8* %142, i64 %150
%152 = load i8, i8* %151
%153 = icmp eq i8 %152, 0
br i1 %153, label %162, label %154
154: ; preds = %172, %167, %162, %149
%155 = phi i64 [ %150, %149 ], [ %163, %162 ], [ %168, %167 ], [ %173, %172 ]
%156 = phi i8 [ %152, %149 ], [ %165, %162 ], [ %170, %167 ], [ %175, %172 ]
%157 = trunc i64 %155 to i32
%158 = sext i8 %156 to i32
%159 = load i32, i32* @stderr
%160 = tail call i32 (i32, i8*, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 %158, i32 %157)
%161 = tail call i32 @exit(i32 1)
unreachable
162: ; preds = %149
%163 = or i64 %150, 1
%164 = getelementptr inbounds i8, i8* %142, i64 %163
%165 = load i8, i8* %164
%166 = icmp eq i8 %165, 0
br i1 %166, label %167, label %154
167: ; preds = %162
%168 = or i64 %150, 2
%169 = getelementptr inbounds i8, i8* %142, i64 %168
%170 = load i8, i8* %169
%171 = icmp eq i8 %170, 0
br i1 %171, label %172, label %154
172: ; preds = %167
%173 = or i64 %150, 3
%174 = getelementptr inbounds i8, i8* %142, i64 %173
%175 = load i8, i8* %174
%176 = icmp eq i8 %175, 0
br i1 %176, label %177, label %154
177: ; preds = %172
%178 = add nuw nsw i64 %150, 4
%179 = icmp eq i64 %178, 65536
br i1 %179, label %180, label %149
180: ; preds = %177
%181 = tail call i32 @munmap(i8* %142, i32 65536)
%182 = tail call i32 @close(i32 %138)
%183 = tail call i32 @exit(i32 0)
unreachable
}