#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);
int main(int argc, char **argv) {
  int fd, r, 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    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1208 <main+0x68>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xe37(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
je     1250 <main+0xb0>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x400,-0x18(%rbp)
jge    12bc <main+0x11c>
movslq -0x18(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     12a9 <main+0x109>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
movslq -0x18(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edx
ff
mov    -0x18(%rbp),%ecx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12ae <main+0x10e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1257 <main+0xb7>
mov    -0x14(%rbp),%edi
mov    $0x1000,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12fc <main+0x15c>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1341 <main+0x1a1>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xcfe(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%esi
lea    0xcaf(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1390 <main+0x1f0>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
lea    0xd3a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xcaf(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
je     13d8 <main+0x238>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     141d <main+0x27d>
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xc99(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xc22(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2bb4(%rip),%rax
mov    (%rax),%esi
lea    0xbd3(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2bbc(%rip),%rax
mov    (%rax),%edx
mov    0x2b73(%rip),%rax
or     (%rax),%edx
mov    0x2b62(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%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    14ac <main+0x30c>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xb93(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x10000,-0x18(%rbp)
jge    151e <main+0x37e>
mov    -0x428(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     150b <main+0x36b>
mov    0x2ae1(%rip),%rax
mov    (%rax),%edi
mov    -0x428(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0x18(%rbp),%ecx
lea    0xc17(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1510 <main+0x370>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    14b3 <main+0x313>
mov    -0x428(%rbp),%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2a92(%rip),%rax
mov    (%rax),%esi
lea    0xab9(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2aa2(%rip),%rax
mov    (%rax),%edx
mov    0x2a89(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%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    15bd <main+0x41d>
mov    0x2a29(%rip),%rax
mov    (%rax),%edi
lea    0xba0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xa82(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x10000,-0x18(%rbp)
jge    162f <main+0x48f>
mov    -0x428(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     161c <main+0x47c>
mov    0x29d0(%rip),%rax
mov    (%rax),%edi
mov    -0x428(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    -0x18(%rbp),%ecx
lea    0xb50(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1621 <main+0x481>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    15c4 <main+0x424>
mov    -0x428(%rbp),%rdi
mov    $0x10000,%esi
call   1090 <munmap@plt>
mov    -0x14(%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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %6
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 1024)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 1024
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i32, i32* %8
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %20
store i32 0, i32* %7
br label %32
32: ; preds = %53, %31
%33 = load i32, i32* %7
%34 = icmp slt i32 %33, 1024
br i1 %34, label %35, label %56
35: ; preds = %32
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %52
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = load i32, i32* %7
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %48, i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %35
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %32
56: ; preds = %32
%57 = load i32, i32* %6
%58 = call i32 @lseek(i32 %57, i32 4096, i32 0)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i32, i32* %8
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %56
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = load i32, i32* %8
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %73)
%75 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %66
%78 = load i32, i32* @O_WRONLY
%79 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %78)
store i32 %79, i32* %6
%80 = load i32, i32* %6
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %77
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%85 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %77
%88 = load i32, i32* %6
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%90 = call i32 @write(i32 %88, i8* %89, i32 1024)
store i32 %90, i32* %8
%91 = load i32, i32* %8
%92 = icmp ne i32 %91, 1024
br i1 %92, label %93, label %98
93: ; preds = %87
%94 = load i32, i32* @stderr
%95 = load i32, i32* %8
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %87
%99 = load i32, i32* %6
%100 = call i32 @close(i32 %99)
store i32 %100, i32* %8
%101 = load i32, i32* %8
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %109
103: ; preds = %98
%104 = load i32, i32* @stderr
%105 = load i32, i32* %8
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %105)
%107 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %98
%110 = load i32, i32* @O_RDWR
%111 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %110)
store i32 %111, i32* %6
%112 = load i32, i32* @PROT_READ
%113 = load i32, i32* @PROT_WRITE
%114 = or i32 %112, %113
%115 = load i32, i32* @MAP_PRIVATE
%116 = load i32, i32* %6
%117 = call i64 @mmap(i32 0, i32 65536, i32 %114, i32 %115, i32 %116, i32 0)
%118 = inttoptr i64 %117 to i8*
store i8* %118, i8** %10
%119 = load i8*, i8** %10
%120 = icmp eq i8* %119, inttoptr (i64 -1 to i8*)
br i1 %120, label %121, label %126
121: ; preds = %109
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%124 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %109
store i32 0, i32* %7
br label %127
127: ; preds = %150, %126
%128 = load i32, i32* %7
%129 = icmp slt i32 %128, 65536
br i1 %129, label %130, label %153
130: ; preds = %127
%131 = load i8*, i8** %10
%132 = load i32, i32* %7
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i8, i8* %131, i64 %133
%135 = load i8, i8* %134
%136 = sext i8 %135 to i32
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %149
138: ; preds = %130
%139 = load i32, i32* @stderr
%140 = load i8*, i8** %10
%141 = load i32, i32* %7
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i8, i8* %140, i64 %142
%144 = load i8, i8* %143
%145 = sext i8 %144 to i32
%146 = load i32, i32* %7
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %145, i32 %146)
%148 = call i32 @exit(i32 1)
unreachable
149: ; preds = %130
br label %150
150: ; preds = %149
%151 = load i32, i32* %7
%152 = add nsw i32 %151, 1
store i32 %152, i32* %7
br label %127
153: ; preds = %127
%154 = load i8*, i8** %10
%155 = call i32 @munmap(i8* %154, i32 65536)
%156 = load i32, i32* %6
%157 = call i32 @close(i32 %156)
%158 = load i32, i32* @O_RDONLY
%159 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %158)
store i32 %159, i32* %6
%160 = load i32, i32* @PROT_READ
%161 = load i32, i32* @MAP_SHARED
%162 = load i32, i32* %6
%163 = call i64 @mmap(i32 0, i32 65536, i32 %160, i32 %161, i32 %162, i32 0)
%164 = inttoptr i64 %163 to i8*
store i8* %164, i8** %10
%165 = load i8*, i8** %10
%166 = icmp eq i8* %165, inttoptr (i64 -1 to i8*)
br i1 %166, label %167, label %172
167: ; preds = %153
%168 = load i32, i32* @stderr
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%170 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%171 = call i32 @exit(i32 1)
unreachable
172: ; preds = %153
store i32 0, i32* %7
br label %173
173: ; preds = %196, %172
%174 = load i32, i32* %7
%175 = icmp slt i32 %174, 65536
br i1 %175, label %176, label %199
176: ; preds = %173
%177 = load i8*, i8** %10
%178 = load i32, i32* %7
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i8, i8* %177, i64 %179
%181 = load i8, i8* %180
%182 = sext i8 %181 to i32
%183 = icmp ne i32 %182, 0
br i1 %183, label %184, label %195
184: ; preds = %176
%185 = load i32, i32* @stderr
%186 = load i8*, i8** %10
%187 = load i32, i32* %7
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8, i8* %186, i64 %188
%190 = load i8, i8* %189
%191 = sext i8 %190 to i32
%192 = load i32, i32* %7
%193 = call i32 (i32, i8*, ...) @fprintf(i32 %185, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 %191, i32 %192)
%194 = call i32 @exit(i32 1)
unreachable
195: ; preds = %176
br label %196
196: ; preds = %195
%197 = load i32, i32* %7
%198 = add nsw i32 %197, 1
store i32 %198, i32* %7
br label %173
199: ; preds = %173
%200 = load i8*, i8** %10
%201 = call i32 @munmap(i8* %200, i32 65536)
%202 = load i32, i32* %6
%203 = call i32 @close(i32 %202)
%204 = 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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @read(i32 %6, i8* %4, i32 1024)
%15 = icmp eq i32 %14, 1024
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13, %48
%21 = phi i64 [ %49, %48 ], [ 0, %13 ]
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %43, %38, %33, %20
%26 = phi i64 [ %21, %20 ], [ %34, %33 ], [ %39, %38 ], [ %44, %43 ]
%27 = phi i8 [ %23, %20 ], [ %36, %33 ], [ %41, %38 ], [ %46, %43 ]
%28 = trunc i64 %26 to i32
%29 = sext i8 %27 to i32
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %28)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %20
%34 = or i64 %21, 1
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %25
38: ; preds = %33
%39 = or i64 %21, 2
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %25
43: ; preds = %38
%44 = or i64 %21, 3
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 0
br i1 %47, label %48, label %25
48: ; preds = %43
%49 = add nuw nsw i64 %21, 4
%50 = icmp eq i64 %49, 1024
br i1 %50, label %51, label %20
51: ; preds = %48
%52 = tail call i32 @lseek(i32 %6, i32 4096, i32 0)
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %51
%59 = tail call i32 @close(i32 %6)
%60 = icmp eq i32 %59, 0
br i1 %60, label %66, label %61
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = tail call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%64 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%65 = tail call i32 @exit(i32 1)
unreachable
66: ; preds = %58
%67 = load i32, i32* @O_WRONLY
%68 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%73 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%74 = tail call i32 @exit(i32 1)
unreachable
75: ; preds = %66
%76 = call i32 @write(i32 %68, i8* %4, i32 1024)
%77 = icmp eq i32 %76, 1024
br i1 %77, label %82, label %78
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = tail call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i32 %76)
%81 = tail call i32 @exit(i32 1)
unreachable
82: ; preds = %75
%83 = tail call i32 @close(i32 %68)
%84 = icmp eq i32 %83, 0
br i1 %84, label %90, label %85
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = tail call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %83)
%88 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%89 = tail call i32 @exit(i32 1)
unreachable
90: ; preds = %82
%91 = load i32, i32* @O_RDWR
%92 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %91)
%93 = load i32, i32* @PROT_READ
%94 = load i32, i32* @PROT_WRITE
%95 = or i32 %94, %93
%96 = load i32, i32* @MAP_PRIVATE
%97 = tail call i64 @mmap(i32 0, i32 65536, i32 %95, i32 %96, i32 %92, i32 0)
%98 = inttoptr i64 %97 to i8*
%99 = icmp eq i8* %98, inttoptr (i64 -1 to i8*)
br i1 %99, label %100, label %105
100: ; preds = %90
%101 = load i32, i32* @stderr
%102 = tail call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%103 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%104 = tail call i32 @exit(i32 1)
unreachable
105: ; preds = %90, %133
%106 = phi i64 [ %134, %133 ], [ 0, %90 ]
%107 = getelementptr inbounds i8, i8* %98, i64 %106
%108 = load i8, i8* %107
%109 = icmp eq i8 %108, 0
br i1 %109, label %118, label %110
110: ; preds = %128, %123, %118, %105
%111 = phi i64 [ %106, %105 ], [ %119, %118 ], [ %124, %123 ], [ %129, %128 ]
%112 = phi i8 [ %108, %105 ], [ %121, %118 ], [ %126, %123 ], [ %131, %128 ]
%113 = trunc i64 %111 to i32
%114 = sext i8 %112 to i32
%115 = load i32, i32* @stderr
%116 = tail call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %114, i32 %113)
%117 = tail call i32 @exit(i32 1)
unreachable
118: ; preds = %105
%119 = or i64 %106, 1
%120 = getelementptr inbounds i8, i8* %98, i64 %119
%121 = load i8, i8* %120
%122 = icmp eq i8 %121, 0
br i1 %122, label %123, label %110
123: ; preds = %118
%124 = or i64 %106, 2
%125 = getelementptr inbounds i8, i8* %98, i64 %124
%126 = load i8, i8* %125
%127 = icmp eq i8 %126, 0
br i1 %127, label %128, label %110
128: ; preds = %123
%129 = or i64 %106, 3
%130 = getelementptr inbounds i8, i8* %98, i64 %129
%131 = load i8, i8* %130
%132 = icmp eq i8 %131, 0
br i1 %132, label %133, label %110
133: ; preds = %128
%134 = add nuw nsw i64 %106, 4
%135 = icmp eq i64 %134, 65536
br i1 %135, label %136, label %105
136: ; preds = %133
%137 = tail call i32 @munmap(i8* %98, i32 65536)
%138 = tail call i32 @close(i32 %92)
%139 = load i32, i32* @O_RDONLY
%140 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %139)
%141 = load i32, i32* @PROT_READ
%142 = load i32, i32* @MAP_SHARED
%143 = tail call i64 @mmap(i32 0, i32 65536, i32 %141, i32 %142, i32 %140, i32 0)
%144 = inttoptr i64 %143 to i8*
%145 = icmp eq i8* %144, inttoptr (i64 -1 to i8*)
br i1 %145, label %146, label %151
146: ; preds = %136
%147 = load i32, i32* @stderr
%148 = tail call i32 (i32, i8*, ...) @fprintf(i32 %147, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%149 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%150 = tail call i32 @exit(i32 1)
unreachable
151: ; preds = %136, %179
%152 = phi i64 [ %180, %179 ], [ 0, %136 ]
%153 = getelementptr inbounds i8, i8* %144, i64 %152
%154 = load i8, i8* %153
%155 = icmp eq i8 %154, 0
br i1 %155, label %164, label %156
156: ; preds = %174, %169, %164, %151
%157 = phi i64 [ %152, %151 ], [ %165, %164 ], [ %170, %169 ], [ %175, %174 ]
%158 = phi i8 [ %154, %151 ], [ %167, %164 ], [ %172, %169 ], [ %177, %174 ]
%159 = trunc i64 %157 to i32
%160 = sext i8 %158 to i32
%161 = load i32, i32* @stderr
%162 = tail call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 %160, i32 %159)
%163 = tail call i32 @exit(i32 1)
unreachable
164: ; preds = %151
%165 = or i64 %152, 1
%166 = getelementptr inbounds i8, i8* %144, i64 %165
%167 = load i8, i8* %166
%168 = icmp eq i8 %167, 0
br i1 %168, label %169, label %156
169: ; preds = %164
%170 = or i64 %152, 2
%171 = getelementptr inbounds i8, i8* %144, i64 %170
%172 = load i8, i8* %171
%173 = icmp eq i8 %172, 0
br i1 %173, label %174, label %156
174: ; preds = %169
%175 = or i64 %152, 3
%176 = getelementptr inbounds i8, i8* %144, i64 %175
%177 = load i8, i8* %176
%178 = icmp eq i8 %177, 0
br i1 %178, label %179, label %156
179: ; preds = %174
%180 = add nuw nsw i64 %152, 4
%181 = icmp eq i64 %180, 65536
br i1 %181, label %182, label %151
182: ; preds = %179
%183 = tail call i32 @munmap(i8* %144, i32 65536)
%184 = tail call i32 @close(i32 %140)
%185 = tail call i32 @exit(i32 0)
unreachable
}