#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_atime;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IRUSR;
int S_IWUSR;
int /*<<< 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 mounted_noatime(char *);
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, stat_buff2;
  time_t atime1, atime2, atime3;
  char *ch;
  if (mounted_noatime("/tmp") == 1) {
    printf("UNTESTED: The /tmp is mounted noatime\n");
    return 5;
  }
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_13_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);
  if (stat(tmpfname, &stat_buff) == -1) {
    printf("Error at 1st stat(): %s\n", strerror(errno));
    unlink(tmpfname);
    return 2;
  }
  atime1 = stat_buff.st_atime;
  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;
  }
  if (stat(tmpfname, &stat_buff2) == -1) {
    printf("Error at 2nd stat(): %s\n", strerror(errno));
    unlink(tmpfname);
    return 2;
  }
  atime2 = stat_buff2.st_atime;
  sleep(1);
  ch = pa;
  *ch = 'b';
  printf("Time before munmap(): %ld\n", time(NULL));
  munmap(pa, size);
  fsync(fd);
  close(fd);
  if (stat(tmpfname, &stat_buff) == -1) {
    printf("Error at 3rd stat(): %s\n", strerror(errno));
    unlink(tmpfname);
    return 2;
  }
  atime3 = stat_buff.st_atime;
  printf("atime1: %d, atime2: %d, atime3: %d\n", (int)atime1, (int)atime2,
         (int)atime3);
  if (atime1 != atime3 || atime1 != atime2) {
    printf("Test PASSED\n");
    unlink(tmpfname);
    return 0;
  }
  printf("Test FAILED: st_atime was not updated properly\n");
  unlink(tmpfname);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x400,-0x128(%rbp)
lea    0xdbc(%rip),%rdi
call   1070 <mounted_noatime@plt>
cmp    $0x1,%eax
jne    126c <main+0x4c>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1697 <main+0x477>
lea    -0x110(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x168(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xd96(%rip),%rdx
call   10a0 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    0x2d12(%rip),%rax
or     (%rax),%esi
mov    0x2cf1(%rip),%rax
or     (%rax),%esi
mov    0x2cd0(%rip),%rax
mov    (%rax),%edx
mov    0x2cef(%rip),%rax
or     (%rax),%edx
call   1120 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    131e <main+0xfe>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1697 <main+0x477>
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    0xcfc(%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     13bf <main+0x19f>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1697 <main+0x477>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
lea    -0x110(%rbp),%rdi
lea    -0x138(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
jne    141e <main+0x1fe>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1697 <main+0x477>
mov    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    $0x1,%edi
call   1140 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%esi
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x128(%rbp),%rsi
mov    0x2b93(%rip),%rax
mov    (%rax),%edx
mov    0x2b42(%rip),%rax
or     (%rax),%edx
mov    0x2b71(%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    0x2aff(%rip),%rcx
cmp    (%rcx),%rax
jne    14d9 <main+0x2b9>
mov    0x2b07(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xbff(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    1697 <main+0x477>
lea    -0x110(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
jne    152c <main+0x30c>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xbbf(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1697 <main+0x477>
mov    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    $0x1,%edi
call   1140 <sleep@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x160(%rbp),%rax
movb   $0x62,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <time@plt>
mov    %eax,%esi
lea    0xb77(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1100 <munmap@plt>
mov    -0x12c(%rbp),%edi
call   1110 <fsync@plt>
mov    -0x12c(%rbp),%edi
call   10c0 <close@plt>
lea    -0x110(%rbp),%rdi
lea    -0x138(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
jne    15f1 <main+0x3d1>
mov    0x29ef(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %rax,%rsi
lea    0xb2e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x2,-0x4(%rbp)
jmp    1697 <main+0x477>
mov    -0x138(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x148(%rbp),%rax
mov    %eax,%esi
mov    -0x150(%rbp),%rax
mov    %eax,%edx
mov    -0x158(%rbp),%rax
mov    %eax,%ecx
lea    0xaf8(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x148(%rbp),%rax
cmp    -0x158(%rbp),%rax
jne    1650 <main+0x430>
mov    -0x148(%rbp),%rax
cmp    -0x150(%rbp),%rax
je     1676 <main+0x456>
lea    0xae6(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    1697 <main+0x477>
lea    0xacd(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
lea    0xdba(%rip),%rdi
call   1080 <mounted_noatime@plt>
cmp    $0x1,%eax
jne    1266 <main+0x36>
lea    0xefa(%rip),%rdi
call   1050 <puts@plt>
mov    $0x5,%ebp
jmp    1523 <main+0x2f3>
xor    %eax,%eax
call   1070 <getpid@plt>
lea    0xd91(%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    0x2d61(%rip),%rax
mov    0x2d32(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d0f(%rip),%rax
or     (%rax),%esi
mov    0x2cee(%rip),%rax
mov    0x2d0f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   1130 <open@plt>
cmp    $0xffffffff,%eax
je     146b <main+0x23b>
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    0xd33(%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    148f <main+0x25f>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     14a6 <main+0x276>
mov    (%rsp),%r14
mov    $0x1,%ebp
mov    $0x1,%edi
call   1150 <sleep@plt>
xor    %edi,%edi
call   10f0 <time@plt>
lea    0xd19(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x2c80(%rip),%rax
mov    0x2c31(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c5e(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%esi
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1090 <mmap@plt>
mov    %rax,%r12
mov    0x2bf8(%rip),%rax
cmp    (%rax),%r12
je     14bd <main+0x28d>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     14de <main+0x2ae>
mov    0x8(%rsp),%r15
mov    $0x1,%edi
call   1150 <sleep@plt>
movb   $0x62,(%r12)
xor    %edi,%edi
call   10f0 <time@plt>
lea    0xcdb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x400,%esi
mov    %r12,%rdi
call   1110 <munmap@plt>
mov    %ebx,%edi
call   1120 <fsync@plt>
mov    %ebx,%edi
call   10d0 <close@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     14f5 <main+0x2c5>
mov    (%rsp),%rbx
lea    0xcca(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   10a0 <printf@plt>
cmp    %rbx,%r14
jne    1535 <main+0x305>
cmp    %r15,%r14
jne    1535 <main+0x305>
lea    0xcc4(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    $0x1,%ebp
jmp    1523 <main+0x2f3>
mov    0x2b3e(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xb9b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    151e <main+0x2ee>
mov    0x2b1a(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xba6(%rip),%rdi
jmp    150a <main+0x2da>
mov    0x2b03(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xba5(%rip),%rdi
jmp    150a <main+0x2da>
mov    0x2aec(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbc0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    1541 <main+0x311>
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbb2(%rip),%rdi
jmp    150a <main+0x2da>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbcf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc09(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
jmp    1523 <main+0x2f3>

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

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