#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;
struct statfs {
  int f_type;
};
typedef int pid_t;

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ MS_SYNC;
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, size_t);
int getpid();
char *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ msync(char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, size_t);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ statfs(char *, struct statfs *);
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;
  size_t len;
  int fd;
  pid_t child;
  int i, exit_val;
  page_size = sysconf(_SC_PAGE_SIZE);
  len = page_size / 2;
  struct statfs buf;
  if (statfs("/tmp", &buf)) {
    printf("Error at statfs(): %s\n", strerror(errno));
    return 2;
  }
  if (buf.f_type == 0x01021994) {
    printf("From mmap(2) manpage, skip known bug on tmpfs\n");
    return 5;
  }
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_11_5_%d", getpid());
  child = fork();
  switch (child) {
  case 0:
    unlink(tmpfname);
    fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
    if (fd == -1) {
      printf("Error at 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';
    msync(pa, len, MS_SYNC);
    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 = open(tmpfname, O_RDWR, 0);
  unlink(tmpfname);
  pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (pa == MAP_FAILED) {
    printf("Error at 2nd mmap(): %s\n", strerror(errno));
    return 1;
  }
  if (pa[len + 1] == 'b') {
    printf("Test FAILED: Modification of the partial page "
           "at the end of an object is written out\n");
    return 1;
  }
  close(fd);
  munmap(pa, len);
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x128(%rbp)
lea    0xdaa(%rip),%rdi
lea    -0x140(%rbp),%rsi
call   10b0 <statfs@plt>
cmp    $0x0,%rax
je     1297 <main+0x87>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
cmpl   $0x1021994,-0x140(%rbp)
19 02 01
jne    12c1 <main+0xb1>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
xor    %eax,%eax
mov    %al,-0x145(%rbp)
call   1040 <getpid@plt>
mov    %eax,%ecx
lea    0xd74(%rip),%rdx
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1080 <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     1535 <main+0x325>
jmp    1313 <main+0x103>
mov    -0x144(%rbp),%eax
test   %eax,%eax
jne    1560 <main+0x350>
jmp    1326 <main+0x116>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
mov    0x2c87(%rip),%rax
or     (%rax),%esi
mov    0x2c66(%rip),%rax
or     (%rax),%esi
mov    0x2c3d(%rip),%rax
mov    (%rax),%edx
mov    0x2c64(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    13a9 <main+0x199>
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
call   1090 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    13ef <main+0x1df>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
mov    -0x128(%rbp),%rsi
mov    0x2bf3(%rip),%rax
mov    (%rax),%edx
mov    0x2b9a(%rip),%rax
or     (%rax),%edx
mov    0x2bd1(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2b4f(%rip),%rcx
cmp    (%rcx),%rax
jne    146d <main+0x25d>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xc36(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
mov    -0x128(%rbp),%rax
mov    %eax,-0x134(%rbp)
movslq -0x134(%rbp),%rax
cmp    -0x118(%rbp),%rax
jge    14dc <main+0x2cc>
mov    -0x120(%rbp),%rax
movslq -0x134(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     14c3 <main+0x2b3>
lea    0xbf5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
jmp    14c8 <main+0x2b8>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    147a <main+0x26a>
mov    -0x120(%rbp),%rax
mov    -0x128(%rbp),%rcx
movb   $0x62,0x1(%rax,%rcx,1)
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    0x2aa4(%rip),%rax
mov    (%rax),%edx
call   1050 <msync@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   10c0 <munmap@plt>
mov    -0x12c(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
mov    0x2a74(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xba2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
jmp    1565 <main+0x355>
lea    -0x138(%rbp),%rdi
call   1120 <wait@plt>
mov    -0x138(%rbp),%edi
call   1100 <WIFEXITED@plt>
cmp    $0x0,%rax
je     159a <main+0x38a>
mov    -0x138(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     15e8 <main+0x3d8>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x138(%rbp),%edi
call   1100 <WIFEXITED@plt>
cmp    $0x0,%rax
je     15ce <main+0x3be>
mov    -0x138(%rbp),%edi
call   10d0 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
lea    0xb2f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
lea    -0x110(%rbp),%rdi
mov    0x29da(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <open@plt>
mov    %eax,-0x12c(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x128(%rbp),%rsi
mov    0x29d1(%rip),%rax
mov    (%rax),%edx
mov    0x2978(%rip),%rax
or     (%rax),%edx
mov    0x29af(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x292d(%rip),%rcx
cmp    (%rcx),%rax
jne    168f <main+0x47f>
mov    0x2945(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xaa1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
mov    -0x120(%rbp),%rax
mov    -0x128(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x62,%eax
jne    16c5 <main+0x4b5>
lea    0xa84(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16f8 <main+0x4e8>
mov    -0x12c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   10c0 <munmap@plt>
lea    0xaa2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   1100 <sysconf@plt>
mov    %rax,%rbx
lea    0xdbb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10c0 <statfs@plt>
test   %rax,%rax
je     127a <main+0x5a>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xd9c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x2,%eax
jmp    1295 <main+0x75>
cmpl   $0x1021994,0x8(%rsp)
01
jne    12a3 <main+0x83>
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd6b(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1090 <snprintf@plt>
xor    %eax,%eax
call   1140 <fork@plt>
cmp    $0xffffffff,%eax
je     13d4 <main+0x1b4>
mov    %rbx,%r14
shr    $0x3f,%r14
add    %rbx,%r14
sar    %r14
test   %eax,%eax
jne    13ee <main+0x1ce>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    0x2cfd(%rip),%rax
mov    0x2cce(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cab(%rip),%rax
or     (%rax),%esi
mov    0x2c82(%rip),%rax
mov    0x2cab(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbp,%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     1439 <main+0x219>
mov    %eax,%r15d
mov    %eax,%edi
mov    %r14,%rsi
call   10a0 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     1469 <main+0x249>
mov    0x2ca1(%rip),%rax
mov    0x2c4a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c7f(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbp
mov    0x2c0b(%rip),%rax
cmp    (%rax),%rbp
je     14f0 <main+0x2d0>
movslq %r14d,%rax
cmp    %rax,%rbx
jle    13a2 <main+0x182>
cmpb   $0x0,0x0(%rbp,%rax,1)
jne    1555 <main+0x335>
add    $0x1,%rax
cmp    %rax,%rbx
jg     138e <main+0x16e>
movb   $0x62,0x1(%r14,%rbp,1)
mov    0x2bf9(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <msync@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10d0 <munmap@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
jmp    154e <main+0x32e>
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc8d(%rip),%rdi
jmp    1269 <main+0x49>
lea    0x4(%rsp),%rdi
call   1130 <wait@plt>
mov    0x4(%rsp),%edi
call   1110 <WIFEXITED@plt>
test   %rax,%rax
je     1413 <main+0x1f3>
mov    0x4(%rsp),%edi
call   10e0 <WEXITSTATUS@plt>
test   %eax,%eax
je     1483 <main+0x263>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    0x4(%rsp),%edi
call   1110 <WIFEXITED@plt>
test   %rax,%rax
je     1453 <main+0x233>
mov    0x4(%rsp),%edi
call   10e0 <WEXITSTATUS@plt>
jmp    1295 <main+0x75>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbe4(%rip),%rdi
jmp    1269 <main+0x49>
lea    0xc93(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%eax
jmp    1295 <main+0x75>
mov    0x2b40(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbc9(%rip),%rdi
jmp    1269 <main+0x49>
mov    0x2b46(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %edx,%edx
call   10f0 <open@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    0x2b44(%rip),%rax
mov    0x2aed(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2b22(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbp
mov    0x2aae(%rip),%rax
cmp    (%rax),%rbp
je     1507 <main+0x2e7>
cmpb   $0x62,0x1(%r14,%rbp,1)
jne    1530 <main+0x310>
lea    0xc23(%rip),%rdi
jmp    155c <main+0x33c>
mov    0x2ab9(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xb5c(%rip),%rdi
jmp    151c <main+0x2fc>
mov    0x2aa2(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xb6f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%eax
jmp    1295 <main+0x75>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10d0 <munmap@plt>
lea    0xbbc(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1295 <main+0x75>
lea    0xb48(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1295 <main+0x75>

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

LLVM IR (-O2):
%struct.statfs = type { i32 }
@_SC_PAGE_SIZE = global i32 0
@.str = [5 x i8] c"/tmp\00"
@.str.1 = [23 x i8] c"Error at statfs(): %s\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"/tmp/pts_mmap_11_5_%d\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [21 x i8] c"Error at open(): %s\0A\00"
@.str.5 = [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.6 = [21 x i8] c"Error at mmap(): %s\0A\00"
@MS_SYNC = global i32 0
@.str.8 = [21 x i8] c"Error at fork(): %s\0A\00"
@.str.10 = [25 x i8] c"Error at 2nd mmap(): %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.13 = [24 x i8] c"Child exited abnormally\00"
@str.14 = [12 x i8] c"Test PASSED\00"
@str.15 = [85 x i8] c"Test FAILED: Modification of the partial page at the end of an object is written out\00"
@str.16 = [46 x i8] c"From mmap(2) manpage, skip known bug on tmpfs\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca %struct.statfs
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = load i32, i32* @_SC_PAGE_SIZE
%7 = tail call i64 @sysconf(i32 %6)
%8 = sdiv i64 %7, 2
%9 = bitcast %struct.statfs* %3 to i8*
%10 = call i64 @statfs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.statfs* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %131
16: ; preds = %0
%17 = getelementptr inbounds %struct.statfs, %struct.statfs* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 16914836
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.16, i64 0, i64 0))
br label %131
22: ; preds = %16
%23 = call i32 (...) @getpid()
%24 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = call i32 (...) @fork()
switch i32 %25, label %86 [
i32 0, label %26
i32 -1, label %82
]
26: ; preds = %22
%27 = call i32 @unlink(i8* %4)
%28 = load i32, i32* @O_CREAT
%29 = load i32, i32* @O_RDWR
%30 = or i32 %29, %28
%31 = load i32, i32* @O_EXCL
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %34, %33
%36 = call i32 @open(i8* %4, i32 %32, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %26
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %40)
br label %131
42: ; preds = %26
%43 = call i32 @ftruncate(i32 %36, i64 %8)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %47)
br label %131
49: ; preds = %42
%50 = load i32, i32* @PROT_READ
%51 = load i32, i32* @PROT_WRITE
%52 = or i32 %51, %50
%53 = load i32, i32* @MAP_SHARED
%54 = call i8* @mmap(i32* null, i64 %8, i32 %52, i32 %53, i32 %36, i32 0)
%55 = load i8*, i8** @MAP_FAILED
%56 = icmp eq i8* %54, %55
br i1 %56, label %57, label %61
57: ; preds = %49
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %59)
br label %131
61: ; preds = %49
%62 = shl i64 %8, 32
%63 = ashr exact i64 %62, 32
%64 = icmp sgt i64 %7, %63
br i1 %64, label %67, label %75
65: ; preds = %67
%66 = icmp sgt i64 %7, %72
br i1 %66, label %67, label %75
67: ; preds = %61, %65
%68 = phi i64 [ %72, %65 ], [ %63, %61 ]
%69 = getelementptr inbounds i8, i8* %54, i64 %68
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 0
%72 = add nsw i64 %68, 1
br i1 %71, label %65, label %73
73: ; preds = %67
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str, i64 0, i64 0))
br label %131
75: ; preds = %65, %61
%76 = add nsw i64 %8, 1
%77 = getelementptr inbounds i8, i8* %54, i64 %76
store i8 98, i8* %77
%78 = load i32, i32* @MS_SYNC
%79 = call i32 @msync(i8* %54, i64 %8, i32 %78)
%80 = call i32 @munmap(i8* %54, i64 %8)
%81 = call i32 @close(i32 %36)
br label %131
82: ; preds = %22
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %84)
br label %131
86: ; preds = %22
%87 = call i32 @wait(i32* %2)
%88 = load i32, i32* %2
%89 = call i64 @WIFEXITED(i32 %88)
%90 = icmp eq i64 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %86
%92 = load i32, i32* %2
%93 = call i32 @WEXITSTATUS(i32 %92)
%94 = icmp eq i32 %93, 0
br i1 %94, label %105, label %95
95: ; preds = %91, %86
%96 = call i32 @unlink(i8* %4)
%97 = load i32, i32* %2
%98 = call i64 @WIFEXITED(i32 %97)
%99 = icmp eq i64 %98, 0
br i1 %99, label %103, label %100
100: ; preds = %95
%101 = load i32, i32* %2
%102 = call i32 @WEXITSTATUS(i32 %101)
br label %131
103: ; preds = %95
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
br label %131
105: ; preds = %91
%106 = load i32, i32* @O_RDWR
%107 = call i32 @open(i8* %4, i32 %106, i32 0)
%108 = call i32 @unlink(i8* %4)
%109 = load i32, i32* @PROT_READ
%110 = load i32, i32* @PROT_WRITE
%111 = or i32 %110, %109
%112 = load i32, i32* @MAP_SHARED
%113 = call i8* @mmap(i32* null, i64 %8, i32 %111, i32 %112, i32 %107, i32 0)
%114 = load i8*, i8** @MAP_FAILED
%115 = icmp eq i8* %113, %114
br i1 %115, label %116, label %120
116: ; preds = %105
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %118)
br label %131
120: ; preds = %105
%121 = add nsw i64 %8, 1
%122 = getelementptr inbounds i8, i8* %113, i64 %121
%123 = load i8, i8* %122
%124 = icmp eq i8 %123, 98
br i1 %124, label %125, label %127
125: ; preds = %120
%126 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.15, i64 0, i64 0))
br label %131
127: ; preds = %120
%128 = call i32 @close(i32 %107)
%129 = call i32 @munmap(i8* %113, i64 %8)
%130 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
br label %131
131: ; preds = %127, %125, %116, %103, %100, %82, %75, %73, %57, %45, %38, %20, %12
%132 = phi i32 [ 2, %12 ], [ 5, %20 ], [ 1, %116 ], [ 1, %125 ], [ 0, %127 ], [ %102, %100 ], [ 2, %103 ], [ 2, %82 ], [ 2, %38 ], [ 2, %45 ], [ 1, %57 ], [ 1, %73 ], [ 0, %75 ]
ret i32 %132
}