#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 PATH_MAX;
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 *, ...);
char *pts_get_tmpdir();
int /*<<< orphan*/ snprintf(char *, int, char *, 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[PATH_MAX];
  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;
  snprintf(tmpfname, sizeof(tmpfname),
           "%s/"
           "pts_mmap_11_4"
           "_pid-%d",
           pts_get_tmpdir(), getpid());
  ;
  struct statfs buf;
  if (statfs(pts_get_tmpdir(), &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;
  }
  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    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x70(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1100 <sysconf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,-0x30(%rbp)
mov    %eax,-0x5c(%rbp)
mov    $0x0,%al
call   10b0 <pts_get_tmpdir@plt>
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x68(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x58(%rbp),%rcx
mov    %eax,%r8d
lea    0xd49(%rip),%rdx
call   1080 <snprintf@plt>
mov    $0x0,%al
call   10b0 <pts_get_tmpdir@plt>
mov    %rax,%rdi
lea    -0x48(%rbp),%rsi
call   10c0 <statfs@plt>
cmp    $0x0,%rax
je     130b <main+0xeb>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
cmpl   $0x1021994,-0x48(%rbp)
jne    1339 <main+0x119>
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x5,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
xor    %eax,%eax
call   1140 <fork@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0xffffffff,%eax
je     154e <main+0x32e>
jmp    1357 <main+0x137>
mov    -0x74(%rbp),%eax
test   %eax,%eax
jne    1580 <main+0x360>
jmp    1367 <main+0x147>
mov    -0x68(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x68(%rbp),%rdi
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
mov    0x2c44(%rip),%rax
or     (%rax),%esi
mov    0x2c23(%rip),%rax
or     (%rax),%esi
mov    0x2bfa(%rip),%rax
mov    (%rax),%edx
mov    0x2c21(%rip),%rax
or     (%rax),%edx
call   10f0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    13e5 <main+0x1c5>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xc93(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1090 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    142c <main+0x20c>
mov    0x2ba7(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    -0x30(%rbp),%rsi
mov    0x2bb9(%rip),%rax
mov    (%rax),%edx
mov    0x2b58(%rip),%rax
or     (%rax),%edx
mov    0x2b8f(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2b16(%rip),%rcx
cmp    (%rcx),%rax
jne    14a5 <main+0x285>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    -0x30(%rbp),%rax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1503 <main+0x2e3>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     14f0 <main+0x2d0>
lea    0xbcc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
jmp    14f5 <main+0x2d5>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    14ac <main+0x28c>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x62,0x1(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2a81(%rip),%rax
mov    (%rax),%edx
call   1050 <msync@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10d0 <munmap@plt>
mov    -0x34(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xb86(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
jmp    1585 <main+0x365>
lea    -0x40(%rbp),%rdi
call   1130 <wait@plt>
mov    -0x40(%rbp),%edi
call   1110 <WIFEXITED@plt>
cmp    $0x0,%rax
je     15b1 <main+0x391>
mov    -0x40(%rbp),%edi
call   10e0 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     1604 <main+0x3e4>
mov    -0x68(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x40(%rbp),%edi
call   1110 <WIFEXITED@plt>
cmp    $0x0,%rax
je     15e3 <main+0x3c3>
mov    -0x40(%rbp),%edi
call   10e0 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
lea    0xb17(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    -0x68(%rbp),%rdi
mov    0x29b9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <open@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,-0x34(%rbp)
call   1030 <unlink@plt>
mov    -0x30(%rbp),%rsi
mov    0x29c1(%rip),%rax
mov    (%rax),%edx
mov    0x2960(%rip),%rax
or     (%rax),%edx
mov    0x2997(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x291e(%rip),%rcx
cmp    (%rcx),%rax
jne    169d <main+0x47d>
mov    0x2936(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xa97(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x62,%eax
jne    16d4 <main+0x4b4>
lea    0xa79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1705 <main+0x4e5>
mov    -0x34(%rbp),%edi
call   10a0 <close@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10d0 <munmap@plt>
lea    0xa99(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2d9a(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1110 <sysconf@plt>
mov    %rax,%r15
xor    %eax,%eax
call   10c0 <pts_get_tmpdir@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd7a(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
mov    %eax,%r8d
call   1090 <snprintf@plt>
xor    %eax,%eax
call   10c0 <pts_get_tmpdir@plt>
lea    -0x28(%rbp),%rsi
mov    %rax,%rdi
call   10d0 <statfs@plt>
test   %rax,%rax
je     12d5 <main+0xa5>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xd54(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x2,%eax
jmp    12ef <main+0xbf>
cmpl   $0x1021994,-0x28(%rbp)
jne    12fc <main+0xcc>
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1150 <fork@plt>
cmp    $0xffffffff,%eax
je     1408 <main+0x1d8>
mov    %r15,%r14
shr    $0x3f,%r14
add    %r15,%r14
sar    %r14
test   %eax,%eax
jne    1422 <main+0x1f2>
mov    %r12,%rdi
call   1030 <unlink@plt>
mov    0x2cc8(%rip),%rax
mov    0x2c91(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c6e(%rip),%rax
or     (%rax),%esi
mov    0x2c45(%rip),%rax
mov    0x2c6e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r12,%rdi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     1466 <main+0x236>
mov    %eax,%r12d
mov    %eax,%edi
mov    %r14,%rsi
call   10a0 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     1496 <main+0x266>
mov    0x2c6c(%rip),%rax
mov    0x2c0d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c42(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbx
mov    0x2bce(%rip),%rax
cmp    (%rax),%rbx
je     1519 <main+0x2e9>
movslq %r14d,%rax
cmp    %rax,%r15
jle    13d6 <main+0x1a6>
cmpb   $0x0,(%rbx,%rax,1)
jne    157f <main+0x34f>
add    $0x1,%rax
cmp    %rax,%r15
jg     13c3 <main+0x193>
movb   $0x62,0x1(%r14,%rbx,1)
mov    0x2bbd(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <msync@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10e0 <munmap@plt>
mov    %r12d,%edi
call   10b0 <close@plt>
jmp    1578 <main+0x348>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xc56(%rip),%rdi
jmp    12c4 <main+0x94>
lea    -0x24(%rbp),%rdi
call   1140 <wait@plt>
mov    -0x24(%rbp),%edi
call   1120 <WIFEXITED@plt>
test   %rax,%rax
je     1444 <main+0x214>
mov    -0x24(%rbp),%edi
call   10f0 <WEXITSTATUS@plt>
test   %eax,%eax
je     14b0 <main+0x280>
mov    %r12,%rdi
call   1030 <unlink@plt>
mov    -0x24(%rbp),%edi
call   1120 <WIFEXITED@plt>
test   %rax,%rax
je     1480 <main+0x250>
mov    -0x24(%rbp),%edi
call   10f0 <WEXITSTATUS@plt>
jmp    12ef <main+0xbf>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xbb4(%rip),%rdi
jmp    12c4 <main+0x94>
lea    0xc63(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%eax
jmp    12ef <main+0xbf>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb99(%rip),%rdi
jmp    12c4 <main+0x94>
mov    0x2b11(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
xor    %edx,%edx
call   1100 <open@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1030 <unlink@plt>
mov    0x2b1b(%rip),%rax
mov    0x2abc(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2af1(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%rbx
mov    0x2a7d(%rip),%rax
cmp    (%rax),%rbx
je     1530 <main+0x300>
cmpb   $0x62,0x1(%r14,%rbx,1)
jne    1559 <main+0x329>
lea    0xbf7(%rip),%rdi
jmp    1586 <main+0x356>
mov    0x2a88(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb30(%rip),%rdi
jmp    1545 <main+0x315>
mov    0x2a71(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb43(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%eax
jmp    12ef <main+0xbf>
mov    %r15d,%edi
call   10b0 <close@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10e0 <munmap@plt>
lea    0xb8f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    12ef <main+0xbf>
lea    0xb1b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    12ef <main+0xbf>

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

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