#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 scalar_t__ 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*/ free(char *);
int /*<<< orphan*/ fsync(int);
int getpid();
char *malloc(scalar_t__);
int /*<<< orphan*/ memset(char *, char, scalar_t__);
void *mmap(int /*<<< orphan*/ *, scalar_t__, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ msync(void *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, scalar_t__);
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 *);
scalar_t__ write(int, char *, scalar_t__);
int main(void) {
  char tmpfname[256];
  char *data;
  void *pa;
  ssize_t size = 1024;
  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;
  }
  data = malloc(size);
  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;
  }
  free(data);
  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    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x400,-0x128(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x170(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xd99(%rip),%rdx
call   10a0 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
mov    0x2d41(%rip),%rax
or     (%rax),%esi
mov    0x2d20(%rip),%rax
or     (%rax),%esi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
mov    0x2d1e(%rip),%rax
or     (%rax),%edx
call   1120 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    12ef <main+0xcf>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1663 <main+0x443>
mov    -0x128(%rbp),%rdi
call   10f0 <malloc@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x61,%esi
call   10b0 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%esi
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x12c(%rbp),%edi
mov    -0x118(%rbp),%rsi
mov    -0x128(%rbp),%rdx
call   1050 <write@plt>
cmp    -0x128(%rbp),%rax
je     1390 <main+0x170>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xcd4(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1663 <main+0x443>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1140 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%esi
lea    0xca3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x128(%rbp),%rsi
mov    0x2c23(%rip),%rax
mov    (%rax),%edx
mov    0x2bca(%rip),%rax
or     (%rax),%edx
mov    0x2c01(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2b87(%rip),%rcx
cmp    (%rcx),%rax
jne    1449 <main+0x229>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    1663 <main+0x443>
mov    $0x1,%edi
call   1140 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%esi
lea    0xc22(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
jne    14bf <main+0x29f>
mov    0x2b21(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xc09(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1663 <main+0x443>
mov    -0x140(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x120(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rax
movb   $0x62,(%rax)
mov    $0x1,%edi
call   1140 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%esi
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    0x2a7d(%rip),%rax
mov    (%rax),%edx
call   1070 <msync@plt>
mov    -0x12c(%rbp),%edi
call   1110 <fsync@plt>
lea    -0x110(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1590 <main+0x370>
mov    0x2a50(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xb6b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1663 <main+0x443>
mov    -0x140(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x158(%rbp),%rsi
mov    -0x160(%rbp),%rdx
mov    -0x148(%rbp),%rcx
mov    -0x150(%rbp),%r8
lea    0xb22(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x160(%rbp),%rax
cmp    -0x158(%rbp),%rax
je     15fe <main+0x3de>
mov    -0x150(%rbp),%rax
cmp    -0x148(%rbp),%rax
jne    1624 <main+0x404>
lea    0xb1f(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    1663 <main+0x443>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1100 <munmap@plt>
mov    -0x12c(%rbp),%edi
call   10c0 <close@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
lea    0xb0d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xor    %eax,%eax
call   1070 <getpid@plt>
lea    0xdb1(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   10b0 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    0x2d86(%rip),%rax
mov    0x2d57(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d34(%rip),%rax
or     (%rax),%esi
mov    0x2d0b(%rip),%rax
mov    0x2d34(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   1130 <open@plt>
cmp    $0xffffffff,%eax
je     1468 <main+0x238>
mov    %eax,%ebx
mov    $0x400,%edi
call   1100 <malloc@plt>
mov    %rax,%rbp
mov    $0x400,%edx
mov    %rax,%rdi
mov    $0x61,%esi
call   10c0 <memset@plt>
xor    %edi,%edi
call   10f0 <time@plt>
lea    0xd53(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x400,%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1060 <write@plt>
cmp    $0x400,%rax
jne    1491 <main+0x261>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
mov    $0x1,%edi
call   1150 <sleep@plt>
xor    %edi,%edi
call   10f0 <time@plt>
lea    0xd3a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x2cbf(%rip),%rax
mov    0x2c68(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c9d(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%esi
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1090 <mmap@plt>
mov    %rax,%r14
mov    0x2c2f(%rip),%rax
cmp    (%rax),%r14
je     14c1 <main+0x291>
mov    $0x1,%edi
call   1150 <sleep@plt>
xor    %edi,%edi
call   10f0 <time@plt>
lea    0xd05(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     14ec <main+0x2bc>
mov    (%rsp),%r12
mov    0x8(%rsp),%r15
movb   $0x62,(%r14)
mov    $0x1,%edi
call   1150 <sleep@plt>
xor    %edi,%edi
call   10f0 <time@plt>
lea    0xcfc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
mov    %r14,%rdi
call   1080 <msync@plt>
mov    %ebx,%edi
call   1120 <fsync@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     1503 <main+0x2d3>
mov    (%rsp),%rbp
mov    0x8(%rsp),%r13
lea    0xcdf(%rip),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   10a0 <printf@plt>
cmp    %r12,%rbp
je     151a <main+0x2ea>
cmp    %r15,%r13
je     151a <main+0x2ea>
mov    $0x400,%esi
mov    %r14,%rdi
call   1110 <munmap@plt>
mov    %ebx,%edi
call   10d0 <close@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
lea    0xcc8(%rip),%rdi
call   1050 <puts@plt>
xor    %ebp,%ebp
jmp    1535 <main+0x305>
mov    0x2b41(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xb99(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x2,%ebp
jmp    1535 <main+0x305>
mov    0x2b18(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xb9f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    $0x2,%ebp
jmp    1535 <main+0x305>
mov    0x2ae8(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xb9e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
jmp    1535 <main+0x305>
mov    0x2abd(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xba8(%rip),%rdi
jmp    14a6 <main+0x276>
mov    0x2aa6(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbc4(%rip),%rdi
jmp    14a6 <main+0x276>
lea    0xc0f(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x118,%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 i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store i32 0, i32* %1
store i64 1024, i64* %5
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = call i32 (...) @getpid()
%15 = call i32 @snprintf(i8* %13, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i32 @unlink(i8* %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_RDWR
%21 = or i32 %19, %20
%22 = load i32, i32* @O_EXCL
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IRUSR
%25 = load i32, i32* @S_IWUSR
%26 = or i32 %24, %25
%27 = call i32 @open(i8* %18, i32 %23, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %0
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 2, i32* %1
br label %144
34: ; preds = %0
%35 = load i64, i64* %5
%36 = call i8* @malloc(i64 %35)
store i8* %36, i8** %3
%37 = load i8*, i8** %3
%38 = load i64, i64* %5
%39 = call i32 @memset(i8* %37, i8 signext 97, i64 %38)
%40 = call i32 @time(i32* null)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %6
%43 = load i8*, i8** %3
%44 = load i64, i64* %5
%45 = call i64 @write(i32 %42, i8* %43, i64 %44)
%46 = load i64, i64* %5
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %34
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%53 = call i32 @unlink(i8* %52)
store i32 2, i32* %1
br label %144
54: ; preds = %34
%55 = load i8*, i8** %3
%56 = call i32 @free(i8* %55)
%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 i64, i64* %5
%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* %6
%66 = call i8* @mmap(i32* null, i64 %60, i32 %63, i32 %64, i32 %65, i32 0)
store i8* %66, i8** %4
%67 = load i8*, i8** %4
%68 = load i8*, i8** @MAP_FAILED
%69 = icmp eq i8* %67, %68
br i1 %69, label %70, label %76
70: ; preds = %54
%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
br label %144
76: ; preds = %54
%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* %7)
%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
br label %144
89: ; preds = %76
%90 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%91 = load i64, i64* %90
store i64 %91, i64* %10
%92 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%93 = load i64, i64* %92
store i64 %93, i64* %8
%94 = load i8*, i8** %4
store i8* %94, i8** %12
%95 = load i8*, i8** %12
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** %4
%100 = load i64, i64* %5
%101 = load i32, i32* @MS_SYNC
%102 = call i32 @msync(i8* %99, i64 %100, i32 %101)
%103 = load i32, i32* %6
%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* %7)
%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
br label %144
114: ; preds = %89
%115 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%116 = load i64, i64* %115
store i64 %116, i64* %11
%117 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%118 = load i64, i64* %117
store i64 %118, i64* %9
%119 = load i64, i64* %10
%120 = load i64, i64* %11
%121 = load i64, i64* %8
%122 = load i64, i64* %9
%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* %11
%125 = load i64, i64* %10
%126 = icmp eq i64 %124, %125
br i1 %126, label %131, label %127
127: ; preds = %114
%128 = load i64, i64* %9
%129 = load i64, i64* %8
%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
br label %144
135: ; preds = %127
%136 = load i8*, i8** %4
%137 = load i64, i64* %5
%138 = call i32 @munmap(i8* %136, i64 %137)
%139 = load i32, i32* %6
%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
br label %144
144: ; preds = %135, %131, %108, %83, %70, %48, %30
%145 = load i32, i32* %1
ret i32 %145
}

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