#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 int 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*/ fsync(int);
int getpid();
int /*<<< orphan*/ memset(char *, char, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int mounted_noatime(char *);
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, 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;
  }
  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;
  }
  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    $0x180,%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,-0x178(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x128(%rbp)
lea    0xdab(%rip),%rdi
call   1060 <mounted_noatime@plt>
cmp    $0x1,%eax
jne    1287 <main+0x87>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x5,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
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    0xd7b(%rip),%rdx
call   1090 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
mov    0x2cf7(%rip),%rax
or     (%rax),%esi
mov    0x2cd6(%rip),%rax
or     (%rax),%esi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
mov    0x2cd4(%rip),%rax
or     (%rax),%edx
call   1100 <open@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0xffffffff,-0x134(%rbp)
jne    1343 <main+0x143>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
mov    -0x178(%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    0xceb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x178(%rbp),%rsi
mov    -0x134(%rbp),%edi
mov    -0x114(%rbp),%edx
call   1040 <write@plt>
cmp    -0x114(%rbp),%eax
je     13d8 <main+0x1d8>
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
lea    -0x110(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1435 <main+0x235>
mov    0x2bb5(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
mov    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    $0x1,%edi
call   1120 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%esi
lea    0xc41(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x114(%rbp),%esi
mov    0x2b7d(%rip),%rax
mov    (%rax),%edx
mov    0x2b2c(%rip),%rax
or     (%rax),%edx
mov    0x2b5b(%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    0x2ae9(%rip),%rcx
cmp    (%rcx),%rax
jne    14f9 <main+0x2f9>
mov    0x2af1(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xbe9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
lea    -0x110(%rbp),%rdi
lea    -0x148(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1556 <main+0x356>
mov    0x2a94(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xb9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
mov    -0x148(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    $0x1,%edi
call   1120 <sleep@plt>
mov    -0x130(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rax
movb   $0x62,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%esi
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x130(%rbp),%rdi
mov    -0x114(%rbp),%esi
call   10e0 <munmap@plt>
mov    -0x134(%rbp),%edi
call   10f0 <fsync@plt>
mov    -0x134(%rbp),%edi
call   10b0 <close@plt>
lea    -0x110(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1624 <main+0x424>
mov    0x29c6(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xb05(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
mov    -0x140(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x150(%rbp),%rax
mov    %eax,%esi
mov    -0x158(%rbp),%rax
mov    %eax,%edx
mov    -0x160(%rbp),%rax
mov    %eax,%ecx
lea    0xac5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x150(%rbp),%rax
cmp    -0x160(%rbp),%rax
jne    1683 <main+0x483>
mov    -0x150(%rbp),%rax
cmp    -0x158(%rbp),%rax
je     16b3 <main+0x4b3>
lea    0xab3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x16c(%rbp)
jmp    16de <main+0x4de>
lea    0xa90(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x16c(%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    $0x518,%rsp
mov    %rsp,%r13
lea    0xdd5(%rip),%rdi
call   1070 <mounted_noatime@plt>
cmp    $0x1,%eax
jne    124b <main+0x3b>
lea    0xf15(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%ebp
jmp    14fa <main+0x2ea>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdac(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   10a0 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2d7c(%rip),%rax
mov    0x2d4d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d2a(%rip),%rax
or     (%rax),%esi
mov    0x2d09(%rip),%rax
mov    0x2d2a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     1442 <main+0x232>
mov    %eax,%ebx
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x61,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd53(%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    1466 <main+0x256>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
je     147d <main+0x26d>
mov    (%rsp),%r14
mov    $0x1,%ebp
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd42(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2ca9(%rip),%rax
mov    0x2c5a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c87(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x400,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,%r12
mov    0x2c21(%rip),%rax
cmp    (%rax),%r12
je     1494 <main+0x284>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
je     14b5 <main+0x2a5>
mov    0x8(%rsp),%r15
mov    $0x1,%edi
call   1130 <sleep@plt>
movb   $0x62,(%r12)
xor    %edi,%edi
call   10e0 <time@plt>
lea    0xd04(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r12,%rdi
mov    $0x400,%esi
call   10f0 <munmap@plt>
mov    %ebx,%edi
call   1100 <fsync@plt>
mov    %ebx,%edi
call   10c0 <close@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10d0 <stat@plt>
cmp    $0xffffffff,%eax
je     14cc <main+0x2bc>
mov    (%rsp),%rbx
lea    0xcf3(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1090 <printf@plt>
cmp    %rbx,%r14
jne    1511 <main+0x301>
cmp    %r15,%r14
jne    1511 <main+0x301>
lea    0xced(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    $0x1,%ebp
jmp    14fa <main+0x2ea>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbc4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    14f5 <main+0x2e5>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbcf(%rip),%rdi
jmp    14e1 <main+0x2d1>
mov    0x2b2c(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbce(%rip),%rdi
jmp    14e1 <main+0x2d1>
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbe9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    151d <main+0x30d>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbdb(%rip),%rdi
jmp    14e1 <main+0x2d1>
mov    0x2add(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbf8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    $0x2,%ebp
mov    %r13,%rsp
mov    %ebp,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc2d(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
jmp    14fa <main+0x2ea>

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 i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca %struct.stat
%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 = call i32 @mounted_noatime(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 5, i32* %1
store i32 1, i32* %14
br label %152
23: ; preds = %0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%25 = call i32 (...) @getpid()
%26 = call i32 @snprintf(i8* %24, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%28 = call i32 @unlink(i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%30 = load i32, i32* @O_CREAT
%31 = load i32, i32* @O_RDWR
%32 = or i32 %30, %31
%33 = load i32, i32* @O_EXCL
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %35, %36
%38 = call i32 @open(i8* %29, i32 %34, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %23
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %43)
store i32 2, i32* %1
store i32 1, i32* %14
br label %152
45: ; preds = %23
%46 = load i32, i32* %3
%47 = call i32 @memset(i8* %18, i8 signext 97, i32 %46)
%48 = call i32 @time(i32* null)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %7
%51 = load i32, i32* %3
%52 = call i32 @write(i32 %50, i8* %18, i32 %51)
%53 = load i32, i32* %3
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %61
55: ; preds = %45
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %57)
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%60 = call i32 @unlink(i8* %59)
store i32 2, i32* %1
store i32 1, i32* %14
br label %152
61: ; preds = %45
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%63 = call i32 @stat(i8* %62, %struct.stat* %8)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %71
65: ; preds = %61
%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
store i32 1, i32* %14
br label %152
71: ; preds = %61
%72 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%73 = load i64, i64* %72
store i64 %73, i64* %10
%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 i32, i32* %3
%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* %7
%83 = call i8* @mmap(i32* null, i32 %77, i32 %80, i32 %81, i32 %82, i32 0)
store i8* %83, i8** %6
%84 = load i8*, i8** %6
%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
store i32 1, i32* %14
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* %9)
%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
store i32 1, i32* %14
br label %152
103: ; preds = %93
%104 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%105 = load i64, i64* %104
store i64 %105, i64* %11
%106 = call i32 @sleep(i32 1)
%107 = load i8*, i8** %6
store i8* %107, i8** %13
%108 = load i8*, i8** %13
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** %6
%112 = load i32, i32* %3
%113 = call i32 @munmap(i8* %111, i32 %112)
%114 = load i32, i32* %7
%115 = call i32 @fsync(i32 %114)
%116 = load i32, i32* %7
%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* %8)
%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
store i32 1, i32* %14
br label %152
127: ; preds = %103
%128 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%129 = load i64, i64* %128
store i64 %129, i64* %12
%130 = load i64, i64* %10
%131 = trunc i64 %130 to i32
%132 = load i64, i64* %11
%133 = trunc i64 %132 to i32
%134 = load i64, i64* %12
%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* %10
%138 = load i64, i64* %12
%139 = icmp ne i64 %137, %138
br i1 %139, label %144, label %140
140: ; preds = %127
%141 = load i64, i64* %10
%142 = load i64, i64* %11
%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
store i32 1, i32* %14
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
store i32 1, i32* %14
br label %152
152: ; preds = %148, %144, %121, %97, %87, %65, %55, %41, %21
%153 = load i8*, i8** %4
%154 = load i32, i32* %1
ret i32 %154
}

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