#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ tmpfname;
typedef int ssize_t;
typedef int pid_t;

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IRUSR;
int S_IWUSR;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ _SC_PAGE_SIZE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int fork();
int ftruncate(int, int);
int getpid();
char *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int shm_open(char *, int, int);
int /*<<< orphan*/ shm_unlink(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strerror(int /*<<< orphan*/);
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ wait(int *);
int main(void) {
  char tmpfname[256];
  long page_size;
  char *pa, ch;
  ssize_t len;
  int fd;
  pid_t child;
  int i, exit_val, ret, size;
  page_size = sysconf(_SC_PAGE_SIZE);
  len = page_size / 2;
  snprintf(tmpfname, sizeof(tmpfname), "pts_mmap_11_5_%d", getpid());
  child = fork();
  switch (child) {
  case 0:
    shm_unlink(tmpfname);
    fd = shm_open(tmpfname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    if (fd == -1) {
      printf("Error at shm_open(): %s\n", strerror(errno));
      return 2;
    }
    if (ftruncate(fd, len) == -1) {
      printf("Error at ftruncate(): %s\n", strerror(errno));
      return 2;
    }
    pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (pa == MAP_FAILED) {
      printf("Error at mmap(): %s\n", strerror(errno));
      return 1;
    }
    for (i = len; i < page_size; i++)
      if (pa[i] != 0) {
        printf("Test FAILED: The partial page at the "
               "end of an object is not zero-filled\n");
        return 1;
      }
    pa[len + 1] = 'b';
    munmap(pa, len);
    close(fd);
    return 0;
  case -1:
    printf("Error at fork(): %s\n", strerror(errno));
    return 2;
  default:
    break;
  }
  wait(&exit_val);
  if (!(WIFEXITED(exit_val) && (WEXITSTATUS(exit_val) == 0))) {
    unlink(tmpfname);
    if (WIFEXITED(exit_val))
      return WEXITSTATUS(exit_val);
    printf("Child exited abnormally\n");
    return 2;
  }
  fd = shm_open(tmpfname, O_RDWR, 0);
  shm_unlink(tmpfname);
  size = 0;
  while ((ret = read(fd, &ch, 1)) == 1) {
    if (ch != 0) {
      printf("File is not zeroed\n");
      return 1;
    }
    size += ret;
  }
  if (ret == -1) {
    printf("Error at read(): %s\n", strerror(errno));
    return 2;
  }
  if (size != len) {
    printf("File has wrong size\n");
    return 2;
  }
  close(fd);
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   10d0 <sysconf@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rcx,%rax
shr    %rax
mov    %eax,-0x128(%rbp)
xor    %eax,%eax
mov    %al,-0x145(%rbp)
call   1040 <getpid@plt>
mov    %eax,%ecx
lea    0xd99(%rip),%rdx
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1070 <snprintf@plt>
mov    -0x145(%rbp),%al
call   1130 <fork@plt>
mov    %eax,-0x130(%rbp)
mov    -0x130(%rbp),%eax
mov    %eax,-0x144(%rbp)
sub    $0xffffffff,%eax
je     14a9 <main+0x299>
jmp    12a3 <main+0x93>
mov    -0x144(%rbp),%eax
test   %eax,%eax
jne    14d4 <main+0x2c4>
jmp    12b6 <main+0xa6>
lea    -0x110(%rbp),%rdi
call   1110 <shm_unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
mov    0x2d1f(%rip),%rax
or     (%rax),%esi
mov    0x2cd6(%rip),%rax
or     (%rax),%esi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
mov    0x2cd4(%rip),%rax
or     (%rax),%edx
call   10f0 <shm_open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    1339 <main+0x129>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%esi
call   1080 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    137e <main+0x16e>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xcbf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x128(%rbp),%esi
mov    0x2c65(%rip),%rax
mov    (%rax),%edx
mov    0x2c14(%rip),%rax
or     (%rax),%edx
mov    0x2c43(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2bc9(%rip),%rcx
cmp    (%rcx),%rax
jne    13fb <main+0x1eb>
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x128(%rbp),%eax
mov    %eax,-0x134(%rbp)
movslq -0x134(%rbp),%rax
cmp    -0x118(%rbp),%rax
jge    1469 <main+0x259>
mov    -0x120(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1450 <main+0x240>
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    167a <main+0x46a>
jmp    1455 <main+0x245>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1407 <main+0x1f7>
mov    -0x120(%rbp),%rax
mov    -0x128(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x62,(%rax,%rcx,1)
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%esi
call   10b0 <munmap@plt>
mov    -0x12c(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    0x2b00(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xbe2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    167a <main+0x46a>
jmp    14d9 <main+0x2c9>
lea    -0x138(%rbp),%rdi
call   1120 <wait@plt>
mov    -0x138(%rbp),%edi
call   10e0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     150e <main+0x2fe>
mov    -0x138(%rbp),%edi
call   10c0 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     155c <main+0x34c>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x138(%rbp),%edi
call   10e0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1542 <main+0x332>
mov    -0x138(%rbp),%edi
call   10c0 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    167a <main+0x46a>
lea    0xb6f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    167a <main+0x46a>
lea    -0x110(%rbp),%rdi
mov    0x2a66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <shm_open@plt>
mov    %eax,-0x12c(%rbp)
lea    -0x110(%rbp),%rdi
call   1110 <shm_unlink@plt>
movl   $0x0,-0x140(%rbp)
mov    -0x12c(%rbp),%edi
lea    -0x121(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    %eax,-0x13c(%rbp)
cmp    $0x1,%eax
jne    15f6 <main+0x3e6>
movsbl -0x121(%rbp),%eax
cmp    $0x0,%eax
je     15df <main+0x3cf>
lea    0xb05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x13c(%rbp),%eax
add    -0x140(%rbp),%eax
mov    %eax,-0x140(%rbp)
jmp    158f <main+0x37f>
cmpl   $0xffffffff,-0x13c(%rbp)
jne    162e <main+0x41e>
mov    0x29a6(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xaca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x140(%rbp),%eax
cmp    -0x128(%rbp),%eax
je     165a <main+0x44a>
lea    0xab3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    167a <main+0x46a>
mov    -0x12c(%rbp),%edi
call   1090 <close@plt>
lea    0xaa3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdb6(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
xor    %eax,%eax
call   1140 <fork@plt>
cmp    $0xffffffff,%eax
je     1377 <main+0x157>
mov    %r14,%rbx
shr    $0x3f,%rbx
add    %r14,%rbx
sar    %rbx
test   %eax,%eax
jne    1391 <main+0x171>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1120 <shm_unlink@plt>
mov    0x2d3c(%rip),%rax
mov    0x2d5d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d12(%rip),%rax
or     (%rax),%esi
mov    0x2cf1(%rip),%rax
mov    0x2d12(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbp,%rdi
call   1100 <shm_open@plt>
cmp    $0xffffffff,%eax
je     13dc <main+0x1bc>
mov    %eax,%ebp
mov    %eax,%edi
mov    %ebx,%esi
call   1090 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     1407 <main+0x1e7>
mov    0x2d0a(%rip),%rax
mov    0x2cbb(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2ce8(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    0x2c80(%rip),%rcx
cmp    (%rcx),%rax
je     14a5 <main+0x285>
movslq %ebx,%rcx
cmp    %rcx,%r14
jle    1343 <main+0x123>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rax,%rcx,1)
jne    14e4 <main+0x2c4>
add    $0x1,%rcx
cmp    %rcx,%r14
jg     1330 <main+0x110>
mov    %rbx,%rcx
shl    $0x20,%rcx
movabs $0x100000000,%rdx
add    %rcx,%rdx
sar    $0x20,%rdx
movb   $0x62,(%rax,%rdx,1)
mov    %rax,%rdi
mov    %ebx,%esi
call   10c0 <munmap@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    1499 <main+0x279>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xccd(%rip),%rdi
jmp    148a <main+0x26a>
lea    0xc(%rsp),%rdi
call   1130 <wait@plt>
mov    0xc(%rsp),%edi
call   10f0 <WIFEXITED@plt>
test   %rax,%rax
je     13b6 <main+0x196>
mov    0xc(%rsp),%edi
call   10d0 <WEXITSTATUS@plt>
test   %eax,%eax
je     141e <main+0x1fe>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    0xc(%rsp),%edi
call   10f0 <WIFEXITED@plt>
test   %rax,%rax
je     13f6 <main+0x1d6>
mov    0xc(%rsp),%edi
call   10d0 <WEXITSTATUS@plt>
jmp    1499 <main+0x279>
mov    0x2bcd(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc20(%rip),%rdi
jmp    148a <main+0x26a>
lea    0xccf(%rip),%rdi
call   1040 <puts@plt>
jmp    1494 <main+0x274>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc0e(%rip),%rdi
jmp    148a <main+0x26a>
mov    0x2bab(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1100 <shm_open@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1120 <shm_unlink@plt>
lea    0xb(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
cmp    $0x1,%eax
jne    1470 <main+0x250>
cmpb   $0x0,0xb(%rsp)
jne    14db <main+0x2bb>
add    $0xffffffff,%ebx
jmp    1450 <main+0x230>
cmp    $0xffffffff,%eax
jne    14cb <main+0x2ab>
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbe4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb8a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    1499 <main+0x279>
test   %ebx,%ebx
je     14f7 <main+0x2d7>
lea    0xc1a(%rip),%rdi
jmp    13fd <main+0x1dd>
lea    0xc22(%rip),%rdi
jmp    14eb <main+0x2cb>
lea    0xb98(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1499 <main+0x279>
mov    %ebp,%edi
call   10a0 <close@plt>
lea    0xbdf(%rip),%rdi
call   1040 <puts@plt>
jmp    1370 <main+0x150>

LLVM IR (-O0):
@_SC_PAGE_SIZE = global i32 0
@.str = [17 x i8] c"pts_mmap_11_5_%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [25 x i8] c"Error at shm_open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"Error at ftruncate(): %s\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [21 x i8] c"Error at mmap(): %s\0A\00"
@.str.4 = [74 x i8] c"Test FAILED: The partial page at the end of an object is not zero-filled\0A\00"
@.str.5 = [21 x i8] c"Error at fork(): %s\0A\00"
@.str.6 = [25 x i8] c"Child exited abnormally\0A\00"
@.str.7 = [20 x i8] c"File is not zeroed\0A\00"
@.str.8 = [21 x i8] c"Error at read(): %s\0A\00"
@.str.9 = [21 x i8] c"File has wrong size\0A\00"
@.str.10 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = load i32, i32* @_SC_PAGE_SIZE
%14 = call i64 @sysconf(i32 %13)
store i64 %14, i64* %3
%15 = load i64, i64* %3
%16 = sdiv i64 %15, 2
%17 = trunc i64 %16 to i32
store i32 %17, i32* %6
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = call i32 (...) @getpid()
%20 = call i32 @snprintf(i8* %18, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @fork()
store i32 %21, i32* %8
%22 = load i32, i32* %8
switch i32 %22, label %102 [
i32 0, label %23
i32 -1, label %98
]
23: ; preds = %0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = call i32 @shm_unlink(i8* %24)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%27 = load i32, i32* @O_RDWR
%28 = load i32, i32* @O_CREAT
%29 = or i32 %27, %28
%30 = load i32, i32* @O_EXCL
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IRUSR
%33 = load i32, i32* @S_IWUSR
%34 = or i32 %32, %33
%35 = call i32 @shm_open(i8* %26, i32 %31, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %23
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %40)
store i32 2, i32* %1
br label %160
42: ; preds = %23
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = call i32 @ftruncate(i32 %43, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %42
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %49)
store i32 2, i32* %1
br label %160
51: ; preds = %42
%52 = load i32, i32* %6
%53 = load i32, i32* @PROT_READ
%54 = load i32, i32* @PROT_WRITE
%55 = or i32 %53, %54
%56 = load i32, i32* @MAP_SHARED
%57 = load i32, i32* %7
%58 = call i8* @mmap(i32* null, i32 %52, i32 %55, i32 %56, i32 %57, i32 0)
store i8* %58, i8** %4
%59 = load i8*, i8** %4
%60 = load i8*, i8** @MAP_FAILED
%61 = icmp eq i8* %59, %60
br i1 %61, label %62, label %66
62: ; preds = %51
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %64)
store i32 1, i32* %1
br label %160
66: ; preds = %51
%67 = load i32, i32* %6
store i32 %67, i32* %9
br label %68
68: ; preds = %84, %66
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = load i64, i64* %3
%72 = icmp slt i64 %70, %71
br i1 %72, label %73, label %87
73: ; preds = %68
%74 = load i8*, i8** %4
%75 = load i32, i32* %9
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %73
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %160
83: ; preds = %73
br label %84
84: ; preds = %83
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
br label %68
87: ; preds = %68
%88 = load i8*, i8** %4
%89 = load i32, i32* %6
%90 = add nsw i32 %89, 1
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %88, i64 %91
store i8 98, i8* %92
%93 = load i8*, i8** %4
%94 = load i32, i32* %6
%95 = call i32 @munmap(i8* %93, i32 %94)
%96 = load i32, i32* %7
%97 = call i32 @close(i32 %96)
store i32 0, i32* %1
br label %160
98: ; preds = %0
%99 = load i32, i32* @errno
%100 = call i8* @strerror(i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %100)
store i32 2, i32* %1
br label %160
102: ; preds = %0
br label %103
103: ; preds = %102
%104 = call i32 @wait(i32* %10)
%105 = load i32, i32* %10
%106 = call i64 @WIFEXITED(i32 %105)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %112
108: ; preds = %103
%109 = load i32, i32* %10
%110 = call i32 @WEXITSTATUS(i32 %109)
%111 = icmp eq i32 %110, 0
br i1 %111, label %123, label %112
112: ; preds = %108, %103
%113 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%114 = call i32 @unlink(i8* %113)
%115 = load i32, i32* %10
%116 = call i64 @WIFEXITED(i32 %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %112
%119 = load i32, i32* %10
%120 = call i32 @WEXITSTATUS(i32 %119)
store i32 %120, i32* %1
br label %160
121: ; preds = %112
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %1
br label %160
123: ; preds = %108
%124 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%125 = load i32, i32* @O_RDWR
%126 = call i32 @shm_open(i8* %124, i32 %125, i32 0)
store i32 %126, i32* %7
%127 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%128 = call i32 @shm_unlink(i8* %127)
store i32 0, i32* %12
br label %129
129: ; preds = %139, %123
%130 = load i32, i32* %7
%131 = call i32 @read(i32 %130, i8* %5, i32 1)
store i32 %131, i32* %11
%132 = icmp eq i32 %131, 1
br i1 %132, label %133, label %143
133: ; preds = %129
%134 = load i8, i8* %5
%135 = sext i8 %134 to i32
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %139
137: ; preds = %133
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %160
139: ; preds = %133
%140 = load i32, i32* %11
%141 = load i32, i32* %12
%142 = add nsw i32 %141, %140
store i32 %142, i32* %12
br label %129
143: ; preds = %129
%144 = load i32, i32* %11
%145 = icmp eq i32 %144, -1
br i1 %145, label %146, label %150
146: ; preds = %143
%147 = load i32, i32* @errno
%148 = call i8* @strerror(i32 %147)
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %148)
store i32 2, i32* %1
br label %160
150: ; preds = %143
%151 = load i32, i32* %12
%152 = load i32, i32* %6
%153 = icmp ne i32 %151, %152
br i1 %153, label %154, label %156
154: ; preds = %150
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
store i32 2, i32* %1
br label %160
156: ; preds = %150
%157 = load i32, i32* %7
%158 = call i32 @close(i32 %157)
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %1
br label %160
160: ; preds = %156, %154, %146, %137, %121, %118, %98, %87, %81, %62, %47, %38
%161 = load i32, i32* %1
ret i32 %161
}

LLVM IR (-O2):
@_SC_PAGE_SIZE = global i32 0
@.str = [17 x i8] c"pts_mmap_11_5_%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [25 x i8] c"Error at shm_open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"Error at ftruncate(): %s\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [21 x i8] c"Error at mmap(): %s\0A\00"
@.str.5 = [21 x i8] c"Error at fork(): %s\0A\00"
@.str.8 = [21 x i8] c"Error at read(): %s\0A\00"
@str = [73 x i8] c"Test FAILED: The partial page at the end of an object is not zero-filled\00"
@str.11 = [24 x i8] c"Child exited abnormally\00"
@str.12 = [12 x i8] c"Test PASSED\00"
@str.13 = [20 x i8] c"File has wrong size\00"
@str.14 = [19 x i8] c"File is not zeroed\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @_SC_PAGE_SIZE
%7 = tail call i64 @sysconf(i32 %6)
%8 = sdiv i64 %7, 2
%9 = trunc i64 %8 to i32
%10 = tail call i32 (...) @getpid()
%11 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @fork()
switch i32 %12, label %72 [
i32 0, label %13
i32 -1, label %68
]
13: ; preds = %0
%14 = call i32 @shm_unlink(i8* %4)
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = load i32, i32* @O_EXCL
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IRUSR
%21 = load i32, i32* @S_IWUSR
%22 = or i32 %21, %20
%23 = call i32 @shm_open(i8* %4, i32 %19, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %13
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %116
29: ; preds = %13
%30 = call i32 @ftruncate(i32 %23, i32 %9)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %116
36: ; preds = %29
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @PROT_WRITE
%39 = or i32 %38, %37
%40 = load i32, i32* @MAP_SHARED
%41 = call i8* @mmap(i32* null, i32 %9, i32 %39, i32 %40, i32 %23, i32 0)
%42 = load i8*, i8** @MAP_FAILED
%43 = icmp eq i8* %41, %42
br i1 %43, label %48, label %44
44: ; preds = %36
%45 = shl i64 %8, 32
%46 = ashr exact i64 %45, 32
%47 = icmp sgt i64 %7, %46
br i1 %47, label %54, label %62
48: ; preds = %36
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %50)
br label %116
52: ; preds = %54
%53 = icmp sgt i64 %7, %59
br i1 %53, label %54, label %62
54: ; preds = %44, %52
%55 = phi i64 [ %59, %52 ], [ %46, %44 ]
%56 = getelementptr inbounds i8, i8* %41, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 0
%59 = add nsw i64 %55, 1
br i1 %58, label %52, label %60
60: ; preds = %54
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str, i64 0, i64 0))
br label %116
62: ; preds = %52, %44
%63 = add i64 %45, 4294967296
%64 = ashr exact i64 %63, 32
%65 = getelementptr inbounds i8, i8* %41, i64 %64
store i8 98, i8* %65
%66 = call i32 @munmap(i8* %41, i32 %9)
%67 = call i32 @close(i32 %23)
br label %116
68: ; preds = %0
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %70)
br label %116
72: ; preds = %0
%73 = call i32 @wait(i32* %3)
%74 = load i32, i32* %3
%75 = call i64 @WIFEXITED(i32 %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %81, label %77
77: ; preds = %72
%78 = load i32, i32* %3
%79 = call i32 @WEXITSTATUS(i32 %78)
%80 = icmp eq i32 %79, 0
br i1 %80, label %91, label %81
81: ; preds = %77, %72
%82 = call i32 @unlink(i8* %4)
%83 = load i32, i32* %3
%84 = call i64 @WIFEXITED(i32 %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %81
%87 = load i32, i32* %3
%88 = call i32 @WEXITSTATUS(i32 %87)
br label %116
89: ; preds = %81
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
br label %116
91: ; preds = %77
%92 = load i32, i32* @O_RDWR
%93 = call i32 @shm_open(i8* %4, i32 %92, i32 0)
%94 = call i32 @shm_unlink(i8* %4)
br label %95
95: ; preds = %103, %91
%96 = phi i32 [ 0, %91 ], [ %104, %103 ]
%97 = call i32 @read(i32 %93, i8* %2, i32 1)
switch i32 %97, label %109 [
i32 1, label %98
i32 -1, label %105
]
98: ; preds = %95
%99 = load i8, i8* %2
%100 = icmp eq i8 %99, 0
br i1 %100, label %103, label %101
101: ; preds = %98
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
br label %116
103: ; preds = %98
%104 = add nuw nsw i32 %96, 1
br label %95
105: ; preds = %95
%106 = load i32, i32* @errno
%107 = call i8* @strerror(i32 %106)
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %107)
br label %116
109: ; preds = %95
%110 = icmp eq i32 %96, %9
br i1 %110, label %113, label %111
111: ; preds = %109
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
br label %116
113: ; preds = %109
%114 = call i32 @close(i32 %93)
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0))
br label %116
116: ; preds = %113, %111, %105, %101, %89, %86, %68, %62, %60, %48, %32, %25
%117 = phi i32 [ 1, %101 ], [ 2, %105 ], [ 2, %111 ], [ 0, %113 ], [ %88, %86 ], [ 2, %89 ], [ 2, %68 ], [ 2, %25 ], [ 2, %32 ], [ 1, %48 ], [ 1, %60 ], [ 0, %62 ]
ret i32 %117
}