#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 scalar_t__ time_t;
struct stat {
  scalar_t__ st_ctime;
  scalar_t__ st_mtime;
};
typedef int ssize_t;

/* Variables and functions */
void *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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fsync(int);
int getpid();
int /*<<< orphan*/ memset(char *, char, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ msync(void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int stat(char *, struct stat *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int main(void) {
  char tmpfname[256];
  ssize_t size = 1024;
  char data[size];
  void *pa;
  int fd;
  struct stat stat_buff;
  time_t mtime1, mtime2, ctime1, ctime2;
  char *ch;
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_14_1_%d", getpid());
  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;
  }
  memset(data, 'a', size);
  printf("Time before write(): %ld\n", time(NULL));
  if (write(fd, data, size) != size) {
    printf("Error at write(): %s\n", strerror(errno));
    unlink(tmpfname);
    return 2;
  }
  sleep(1);
  printf("Time before mmap(): %ld\n", time(NULL));
  pa = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (pa == MAP_FAILED) {
    printf("Error at mmap: %s\n", strerror(errno));
    unlink(tmpfname);
    return 1;
  }
  sleep(1);
  printf("Time before write reference: %ld\n", time(NULL));
  if (stat(tmpfname, &stat_buff) == -1) {
    printf("Error at 1st stat(): %s\n", strerror(errno));
    unlink(tmpfname);
    return 2;
  }
  ctime1 = stat_buff.st_ctime;
  mtime1 = stat_buff.st_mtime;
  ch = pa;
  *ch = 'b';
  sleep(1);
  printf("Time before msync(): %ld\n", time(NULL));
  msync(pa, size, MS_SYNC);
  fsync(fd);
  if (stat(tmpfname, &stat_buff) == -1) {
    printf("Error at stat(): %s\n", strerror(errno));
    unlink(tmpfname);
    return 2;
  }
  ctime2 = stat_buff.st_ctime;
  mtime2 = stat_buff.st_mtime;
  printf("ctime1: %ld, ctime2: %ld\nmtime1: %ld, mtime2: %ld\n", ctime1, ctime2,
         mtime1, mtime2);
  if (ctime2 == ctime1 || mtime2 == mtime1) {
    printf("Test FAILED: "
           "st_ctime and st_mtime were not updated properly\n");
    unlink(tmpfname);
    return 1;
  }
  munmap(pa, size);
  close(fd);
  unlink(tmpfname);
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x114(%rbp)
mov    -0x114(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x120(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x188(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x128(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x180(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xd88(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
mov    0x2d30(%rip),%rax
or     (%rax),%esi
mov    0x2d0f(%rip),%rax
or     (%rax),%esi
mov    0x2ce6(%rip),%rax
mov    (%rax),%edx
mov    0x2d0d(%rip),%rax
or     (%rax),%edx
call   1100 <open@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0xffffffff,-0x134(%rbp)
jne    130a <main+0x10a>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
jmp    1695 <main+0x495>
mov    -0x188(%rbp),%rdi
mov    -0x114(%rbp),%edx
mov    $0x61,%esi
call   10a0 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%esi
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x188(%rbp),%rsi
mov    -0x134(%rbp),%edi
mov    -0x114(%rbp),%edx
call   1040 <write@plt>
cmp    -0x114(%rbp),%eax
je     139f <main+0x19f>
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
jmp    1695 <main+0x495>
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%esi
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x114(%rbp),%esi
mov    0x2c21(%rip),%rax
mov    (%rax),%edx
mov    0x2bc8(%rip),%rax
or     (%rax),%edx
mov    0x2bff(%rip),%rax
mov    (%rax),%ecx
mov    -0x134(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rax
mov    0x2b85(%rip),%rcx
cmp    (%rcx),%rax
jne    1455 <main+0x255>
mov    0x2b95(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xc48(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
jmp    1695 <main+0x495>
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%esi
lea    0xc16(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x148(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jne    14d5 <main+0x2d5>
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xbfd(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
jmp    1695 <main+0x495>
mov    -0x148(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x170(%rbp),%rax
movb   $0x62,(%rax)
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%esi
lea    0xb9d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x130(%rbp),%rdi
mov    -0x114(%rbp),%esi
mov    0x2a68(%rip),%rax
mov    (%rax),%edx
call   1060 <msync@plt>
mov    -0x134(%rbp),%edi
call   10f0 <fsync@plt>
lea    -0x110(%rbp),%rdi
lea    -0x148(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jne    15af <main+0x3af>
mov    0x2a3b(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xb56(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
jmp    1695 <main+0x495>
mov    -0x148(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x140(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x160(%rbp),%rsi
mov    -0x168(%rbp),%rdx
mov    -0x150(%rbp),%rcx
mov    -0x158(%rbp),%r8
lea    0xb03(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x168(%rbp),%rax
cmp    -0x160(%rbp),%rax
je     161d <main+0x41d>
mov    -0x158(%rbp),%rax
cmp    -0x150(%rbp),%rax
jne    164d <main+0x44d>
lea    0xb00(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
jmp    1695 <main+0x495>
mov    -0x130(%rbp),%rdi
mov    -0x114(%rbp),%esi
call   10e0 <munmap@plt>
mov    -0x134(%rbp),%edi
call   10b0 <close@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    0xae5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x174(%rbp)
mov    -0x120(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x528,%rsp
mov    %rsp,%r15
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdce(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   10a0 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2da3(%rip),%rax
mov    0x2d74(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d51(%rip),%rax
or     (%rax),%esi
mov    0x2d28(%rip),%rax
mov    0x2d51(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     144c <main+0x23c>
mov    %eax,%ebx
lea    0x120(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x61,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd75(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
cmp    $0x400,%eax
jne    1475 <main+0x265>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd65(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2cea(%rip),%rax
mov    0x2c93(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cc8(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x400,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,%r14
mov    0x2c5a(%rip),%rax
cmp    (%rax),%r14
je     14a5 <main+0x295>
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd30(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
je     14d0 <main+0x2c0>
mov    0x10(%rsp),%r12
mov    0x18(%rsp),%rax
mov    %rax,0x8(%rsp)
movb   $0x62,(%r14)
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd1f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   1070 <msync@plt>
mov    %ebx,%edi
call   1100 <fsync@plt>
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
je     14e7 <main+0x2d7>
mov    0x10(%rsp),%rbp
mov    0x18(%rsp),%r13
lea    0xcff(%rip),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    0x8(%rsp),%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1090 <printf@plt>
cmp    %r12,%rbp
je     14fe <main+0x2ee>
cmp    0x8(%rsp),%r13
je     14fe <main+0x2ee>
mov    %r14,%rdi
mov    $0x400,%esi
call   10f0 <munmap@plt>
mov    %ebx,%edi
call   10c0 <close@plt>
lea    0x20(%rsp),%rdi
call   1030 <unlink@plt>
lea    0xce4(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    1519 <main+0x309>
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbb5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x2,%ebp
jmp    1519 <main+0x309>
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbbb(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x20(%rsp),%rdi
call   1030 <unlink@plt>
mov    $0x2,%ebp
jmp    1519 <main+0x309>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbba(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x20(%rsp),%rdi
call   1030 <unlink@plt>
jmp    1519 <main+0x309>
mov    0x2ad9(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbc4(%rip),%rdi
jmp    148a <main+0x27a>
mov    0x2ac2(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbe0(%rip),%rdi
jmp    148a <main+0x27a>
lea    0xc2b(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rdi
call   1030 <unlink@plt>
mov    $0x1,%ebp
mov    %r15,%rsp
mov    %ebp,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [22 x i8] c"/tmp/pts_mmap_14_1_%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.1 = [21 x i8] c"Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"Time before write(): %ld\0A\00"
@.str.3 = [22 x i8] c"Error at write(): %s\0A\00"
@.str.4 = [25 x i8] c"Time before mmap(): %ld\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [19 x i8] c"Error at mmap: %s\0A\00"
@.str.6 = [34 x i8] c"Time before write reference: %ld\0A\00"
@.str.7 = [25 x i8] c"Error at 1st stat(): %s\0A\00"
@.str.8 = [26 x i8] c"Time before msync(): %ld\0A\00"
@MS_SYNC = global i32 0
@.str.9 = [21 x i8] c"Error at stat(): %s\0A\00"
@.str.10 = [51 x i8] c"ctime1: %ld, ctime2: %ld\0Amtime1: %ld, mtime2: %ld\0A\00"
@.str.11 = [62 x i8] c"Test FAILED: st_ctime and st_mtime were not updated properly\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 i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i32
store i32 0, i32* %1
store i32 1024, i32* %3
%15 = load i32, i32* %3
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %4
%18 = alloca i8, i64 %16
store i64 %16, i64* %5
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = call i32 (...) @getpid()
%21 = call i32 @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%23 = call i32 @unlink(i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = load i32, i32* @O_CREAT
%26 = load i32, i32* @O_RDWR
%27 = or i32 %25, %26
%28 = load i32, i32* @O_EXCL
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %30, %31
%33 = call i32 @open(i8* %24, i32 %29, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %0
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %38)
store i32 2, i32* %1
store i32 1, i32* %14
br label %144
40: ; preds = %0
%41 = load i32, i32* %3
%42 = call i32 @memset(i8* %18, i8 signext 97, i32 %41)
%43 = call i32 @time(i32* null)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %7
%46 = load i32, i32* %3
%47 = call i32 @write(i32 %45, i8* %18, i32 %46)
%48 = load i32, i32* %3
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %56
50: ; preds = %40
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%55 = call i32 @unlink(i8* %54)
store i32 2, i32* %1
store i32 1, i32* %14
br label %144
56: ; preds = %40
%57 = call i32 @sleep(i32 1)
%58 = call i32 @time(i32* null)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %3
%61 = load i32, i32* @PROT_READ
%62 = load i32, i32* @PROT_WRITE
%63 = or i32 %61, %62
%64 = load i32, i32* @MAP_SHARED
%65 = load i32, i32* %7
%66 = call i8* @mmap(i32* null, i32 %60, i32 %63, i32 %64, i32 %65, i32 0)
store i8* %66, i8** %6
%67 = load i8*, i8** %6
%68 = load i8*, i8** @MAP_FAILED
%69 = icmp eq i8* %67, %68
br i1 %69, label %70, label %76
70: ; preds = %56
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%75 = call i32 @unlink(i8* %74)
store i32 1, i32* %1
store i32 1, i32* %14
br label %144
76: ; preds = %56
%77 = call i32 @sleep(i32 1)
%78 = call i32 @time(i32* null)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %78)
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%81 = call i32 @stat(i8* %80, %struct.stat* %8)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %89
83: ; preds = %76
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %85)
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%88 = call i32 @unlink(i8* %87)
store i32 2, i32* %1
store i32 1, i32* %14
br label %144
89: ; preds = %76
%90 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%91 = load i64, i64* %90
store i64 %91, i64* %11
%92 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%93 = load i64, i64* %92
store i64 %93, i64* %9
%94 = load i8*, i8** %6
store i8* %94, i8** %13
%95 = load i8*, i8** %13
store i8 98, i8* %95
%96 = call i32 @sleep(i32 1)
%97 = call i32 @time(i32* null)
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %97)
%99 = load i8*, i8** %6
%100 = load i32, i32* %3
%101 = load i32, i32* @MS_SYNC
%102 = call i32 @msync(i8* %99, i32 %100, i32 %101)
%103 = load i32, i32* %7
%104 = call i32 @fsync(i32 %103)
%105 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%106 = call i32 @stat(i8* %105, %struct.stat* %8)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %114
108: ; preds = %89
%109 = load i32, i32* @errno
%110 = call i8* @strerror(i32 %109)
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %110)
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%113 = call i32 @unlink(i8* %112)
store i32 2, i32* %1
store i32 1, i32* %14
br label %144
114: ; preds = %89
%115 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%116 = load i64, i64* %115
store i64 %116, i64* %12
%117 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%118 = load i64, i64* %117
store i64 %118, i64* %10
%119 = load i64, i64* %11
%120 = load i64, i64* %12
%121 = load i64, i64* %9
%122 = load i64, i64* %10
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0), i64 %119, i64 %120, i64 %121, i64 %122)
%124 = load i64, i64* %12
%125 = load i64, i64* %11
%126 = icmp eq i64 %124, %125
br i1 %126, label %131, label %127
127: ; preds = %114
%128 = load i64, i64* %10
%129 = load i64, i64* %9
%130 = icmp eq i64 %128, %129
br i1 %130, label %131, label %135
131: ; preds = %127, %114
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.11, i64 0, i64 0))
%133 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%134 = call i32 @unlink(i8* %133)
store i32 1, i32* %1
store i32 1, i32* %14
br label %144
135: ; preds = %127
%136 = load i8*, i8** %6
%137 = load i32, i32* %3
%138 = call i32 @munmap(i8* %136, i32 %137)
%139 = load i32, i32* %7
%140 = call i32 @close(i32 %139)
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%142 = call i32 @unlink(i8* %141)
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %1
store i32 1, i32* %14
br label %144
144: ; preds = %135, %131, %108, %83, %70, %50, %36
%145 = load i8*, i8** %4
%146 = load i32, i32* %1
ret i32 %146
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [22 x i8] c"/tmp/pts_mmap_14_1_%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.1 = [21 x i8] c"Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [26 x i8] c"Time before write(): %ld\0A\00"
@.str.3 = [22 x i8] c"Error at write(): %s\0A\00"
@.str.4 = [25 x i8] c"Time before mmap(): %ld\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.5 = [19 x i8] c"Error at mmap: %s\0A\00"
@.str.6 = [34 x i8] c"Time before write reference: %ld\0A\00"
@.str.7 = [25 x i8] c"Error at 1st stat(): %s\0A\00"
@.str.8 = [26 x i8] c"Time before msync(): %ld\0A\00"
@MS_SYNC = global i32 0
@.str.9 = [21 x i8] c"Error at stat(): %s\0A\00"
@.str.10 = [51 x i8] c"ctime1: %ld, ctime2: %ld\0Amtime1: %ld, mtime2: %ld\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.13 = [61 x i8] c"Test FAILED: st_ctime and st_mtime were not updated properly\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = tail call i8* @llvm.stacksave()
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = bitcast %struct.stat* %2 to i8*
%8 = tail call i32 (...) @getpid()
%9 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @unlink(i8* %3)
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDWR
%13 = or i32 %12, %11
%14 = load i32, i32* @O_EXCL
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %17, %16
%19 = call i32 @open(i8* %3, i32 %15, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %0
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %96
25: ; preds = %0
%26 = call i32 @memset(i8* %6, i8 signext 97, i32 1024)
%27 = call i32 @time(i32* null)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 @write(i32 %19, i8* %6, i32 1024)
%30 = icmp eq i32 %29, 1024
br i1 %30, label %36, label %31
31: ; preds = %25
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = call i32 @unlink(i8* %3)
br label %96
36: ; preds = %25
%37 = call i32 @sleep(i32 1)
%38 = call i32 @time(i32* null)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @PROT_READ
%41 = load i32, i32* @PROT_WRITE
%42 = or i32 %41, %40
%43 = load i32, i32* @MAP_SHARED
%44 = call i8* @mmap(i32* null, i32 1024, i32 %42, i32 %43, i32 %19, i32 0)
%45 = load i8*, i8** @MAP_FAILED
%46 = icmp eq i8* %44, %45
br i1 %46, label %47, label %52
47: ; preds = %36
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %49)
%51 = call i32 @unlink(i8* %3)
br label %96
52: ; preds = %36
%53 = call i32 @sleep(i32 1)
%54 = call i32 @time(i32* null)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %54)
%56 = call i32 @stat(i8* %3, %struct.stat* %2)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %63
58: ; preds = %52
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %60)
%62 = call i32 @unlink(i8* %3)
br label %96
63: ; preds = %52
%64 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%65 = load i64, i64* %64
%66 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%67 = load i64, i64* %66
store i8 98, i8* %44
%68 = call i32 @sleep(i32 1)
%69 = call i32 @time(i32* null)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %69)
%71 = load i32, i32* @MS_SYNC
%72 = call i32 @msync(i8* %44, i32 1024, i32 %71)
%73 = call i32 @fsync(i32 %19)
%74 = call i32 @stat(i8* %3, %struct.stat* %2)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %81
76: ; preds = %63
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %78)
%80 = call i32 @unlink(i8* %3)
br label %96
81: ; preds = %63
%82 = load i64, i64* %64
%83 = load i64, i64* %66
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0), i64 %65, i64 %82, i64 %67, i64 %83)
%85 = icmp eq i64 %82, %65
%86 = icmp eq i64 %83, %67
%87 = select i1 %85, i1 true, i1 %86
br i1 %87, label %88, label %91
88: ; preds = %81
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.13, i64 0, i64 0))
%90 = call i32 @unlink(i8* %3)
br label %96
91: ; preds = %81
%92 = call i32 @munmap(i8* %44, i32 1024)
%93 = call i32 @close(i32 %19)
%94 = call i32 @unlink(i8* %3)
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %96
96: ; preds = %91, %88, %76, %58, %47, %31, %21
%97 = phi i32 [ 2, %21 ], [ 2, %31 ], [ 1, %47 ], [ 2, %58 ], [ 2, %76 ], [ 1, %88 ], [ 0, %91 ]
ret i32 %97
}