#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;

/* Variables and functions */
scalar_t__ ENOTSUP;
void *MAP_FAILED;
int MAP_FIXED;
int MAP_PRIVATE;
int MAP_SHARED;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IRUSR;
int S_IWUSR;
scalar_t__ errno;
int ftruncate(int, int);
int getpid();
char *malloc(int);
void *mmap(void *, size_t, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strerror(scalar_t__);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char tmpfname[256];
  char *data;
  int total_size = 1024;
  void *pa;
  size_t len = total_size;
  int fd, err = 0;
  data = malloc(total_size);
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_27_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;
  }
  unlink(tmpfname);
  if (ftruncate(fd, total_size) == -1) {
    printf("Error at ftruncate(): %s\n", strerror(errno));
    return 2;
  }
  pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  if (pa == MAP_FAILED) {
    if (errno != ENOTSUP) {
      printf("MAP_PRIVATE is not supported\n");
    } else {
      printf("MAP_PRIVATE failed with: %s\n", strerror(errno));
      err++;
    }
  } else {
    printf("MAP_PRIVATE succeeded\n");
    munmap(pa, len);
  }
  pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (pa == MAP_FAILED) {
    printf("Error at mmap(): %s\n", strerror(errno));
    return 2;
  }
  pa = mmap(pa, len / 2, PROT_READ, MAP_SHARED | MAP_FIXED, fd, 0);
  if (pa == MAP_FAILED) {
    if (errno != ENOTSUP) {
      printf("MAP_FIXED is not supported\n");
    } else {
      printf("MAP_FIXED failed with: %s\n", strerror(errno));
      err++;
    }
  } else {
    printf("MAP_FIXED succeeded\n");
    munmap(pa, len);
  }
  if (err)
    return 1;
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x11c(%rbp)
movslq -0x11c(%rbp),%rax
mov    %rax,-0x130(%rbp)
movl   $0x0,-0x138(%rbp)
mov    -0x11c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x140(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xdf0(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
or     (%rax),%esi
mov    0x2d6f(%rip),%rax
or     (%rax),%esi
mov    0x2d4e(%rip),%rax
mov    (%rax),%edx
mov    0x2d6d(%rip),%rax
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0xffffffff,-0x134(%rbp)
jne    1299 <main+0xf9>
mov    0x2d34(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1549 <main+0x3a9>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x134(%rbp),%edi
mov    -0x11c(%rbp),%esi
call   1080 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    12eb <main+0x14b>
mov    0x2ce2(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1549 <main+0x3a9>
mov    -0x130(%rbp),%rsi
mov    0x2cf7(%rip),%rax
mov    (%rax),%edx
mov    0x2c9e(%rip),%rax
or     (%rax),%edx
mov    0x2c85(%rip),%rax
mov    (%rax),%ecx
mov    -0x134(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    0x2c4b(%rip),%rcx
cmp    (%rcx),%rax
jne    139f <main+0x1ff>
mov    0x2c63(%rip),%rax
mov    (%rax),%rax
mov    0x2c79(%rip),%rcx
cmp    (%rcx),%rax
je     136b <main+0x1cb>
lea    0xce6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    139a <main+0x1fa>
mov    0x2c36(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    13c0 <main+0x220>
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   10a0 <munmap@plt>
mov    -0x130(%rbp),%rsi
mov    0x2c22(%rip),%rax
mov    (%rax),%edx
mov    0x2bc9(%rip),%rax
or     (%rax),%edx
mov    0x2c00(%rip),%rax
mov    (%rax),%ecx
mov    -0x134(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    0x2b76(%rip),%rcx
cmp    (%rcx),%rax
jne    143f <main+0x29f>
mov    0x2b8e(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1549 <main+0x3a9>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rsi
shr    $0x1,%rsi
mov    0x2b98(%rip),%rax
mov    (%rax),%edx
mov    0x2b7f(%rip),%rax
mov    (%rax),%ecx
mov    0x2b1e(%rip),%rax
or     (%rax),%ecx
mov    -0x134(%rbp),%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    0x2af0(%rip),%rcx
cmp    (%rcx),%rax
jne    14fa <main+0x35a>
mov    0x2b08(%rip),%rax
mov    (%rax),%rax
mov    0x2b1e(%rip),%rcx
cmp    (%rcx),%rax
je     14c6 <main+0x326>
lea    0xbf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14f5 <main+0x355>
mov    0x2adb(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xbe9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    151b <main+0x37b>
lea    0xbe2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   10a0 <munmap@plt>
cmpl   $0x0,-0x138(%rbp)
je     1534 <main+0x394>
movl   $0x1,-0x4(%rbp)
jmp    1549 <main+0x3a9>
lea    0xbbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe41(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2e18(%rip),%rax
mov    0x2de9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
mov    0x2d9d(%rip),%rax
mov    0x2dbe(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1288 <main+0xe8>
mov    %eax,%ebp
mov    %rsp,%rdi
call   1030 <unlink@plt>
mov    %ebp,%edi
mov    $0x400,%esi
call   1090 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     12a3 <main+0x103>
mov    0x2dbb(%rip),%r14
mov    0x2d64(%rip),%r13
mov    0x0(%r13),%edx
or     (%r14),%edx
mov    0x2d46(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%esi
xor    %edi,%edi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    0x2d1b(%rip),%r15
cmp    (%r15),%rax
je     12be <main+0x11e>
mov    %rax,%rbx
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x400,%esi
mov    %rbx,%rdi
call   10a0 <munmap@plt>
jmp    12fb <main+0x15b>
mov    0x2d19(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd78(%rip),%rdi
jmp    137f <main+0x1df>
mov    0x2cfe(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd72(%rip),%rdi
jmp    137f <main+0x1df>
mov    0x2ce3(%rip),%rax
mov    (%rax),%rdi
mov    0x2cf9(%rip),%rax
cmp    (%rax),%rdi
jne    12ef <main+0x14f>
call   10c0 <strerror@plt>
lea    0xd65(%rip),%rdi
xor    %r12d,%r12d
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12fe <main+0x15e>
lea    0xded(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r12b
mov    0x0(%r13),%edx
or     (%r14),%edx
mov    0x2cd4(%rip),%rbx
mov    (%rbx),%ecx
mov    $0x400,%esi
xor    %edi,%edi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
cmp    (%r15),%rax
je     1369 <main+0x1c9>
mov    (%r14),%edx
mov    0x2c59(%rip),%rcx
mov    (%rcx),%ecx
or     (%rbx),%ecx
mov    $0x200,%esi
mov    %rax,%rdi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
cmp    (%r15),%rax
je     13a0 <main+0x200>
mov    %rax,%rbx
lea    0xd53(%rip),%rdi
call   1040 <puts@plt>
mov    $0x400,%esi
mov    %rbx,%rdi
call   10a0 <munmap@plt>
jmp    13df <main+0x23f>
mov    0x2c38(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xce3(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c01(%rip),%rax
mov    (%rax),%rdi
mov    0x2c17(%rip),%rax
cmp    (%rax),%rdi
jne    13d3 <main+0x233>
call   10c0 <strerror@plt>
lea    0xcb5(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    138e <main+0x1ee>
lea    0xcee(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
test   %r12b,%r12b
je     138e <main+0x1ee>
lea    0xccc(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    138e <main+0x1ee>

LLVM IR (-O0):
@.str = [22 x i8] c"/tmp/pts_mmap_27_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 i64 0
@.str.2 = [26 x i8] c"Error at ftruncate(): %s\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@ENOTSUP = global i64 0
@.str.3 = [30 x i8] c"MAP_PRIVATE is not supported\0A\00"
@.str.4 = [29 x i8] c"MAP_PRIVATE failed with: %s\0A\00"
@.str.5 = [23 x i8] c"MAP_PRIVATE succeeded\0A\00"
@MAP_SHARED = global i32 0
@.str.6 = [21 x i8] c"Error at mmap(): %s\0A\00"
@MAP_FIXED = global i32 0
@.str.7 = [28 x i8] c"MAP_FIXED is not supported\0A\00"
@.str.8 = [27 x i8] c"MAP_FIXED failed with: %s\0A\00"
@.str.9 = [21 x i8] c"MAP_FIXED succeeded\0A\00"
@.str.10 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1024, i32* %4
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
store i64 %10, i64* %6
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %3
%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* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %0
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %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 %126
34: ; preds = %0
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%36 = call i32 @unlink(i8* %35)
%37 = load i32, i32* %7
%38 = load i32, i32* %4
%39 = call i32 @ftruncate(i32 %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i64, i64* @errno
%43 = call i8* @strerror(i64 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 2, i32* %1
br label %126
45: ; preds = %34
%46 = load i64, i64* %6
%47 = load i32, i32* @PROT_READ
%48 = load i32, i32* @PROT_WRITE
%49 = or i32 %47, %48
%50 = load i32, i32* @MAP_PRIVATE
%51 = load i32, i32* %7
%52 = call i8* @mmap(i8* null, i64 %46, i32 %49, i32 %50, i32 %51, i32 0)
store i8* %52, i8** %5
%53 = load i8*, i8** %5
%54 = load i8*, i8** @MAP_FAILED
%55 = icmp eq i8* %53, %54
br i1 %55, label %56, label %69
56: ; preds = %45
%57 = load i64, i64* @errno
%58 = load i64, i64* @ENOTSUP
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %68
62: ; preds = %56
%63 = load i64, i64* @errno
%64 = call i8* @strerror(i64 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %68
68: ; preds = %62, %60
br label %74
69: ; preds = %45
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%71 = load i8*, i8** %5
%72 = load i64, i64* %6
%73 = call i32 @munmap(i8* %71, i64 %72)
br label %74
74: ; preds = %69, %68
%75 = load i64, i64* %6
%76 = load i32, i32* @PROT_READ
%77 = load i32, i32* @PROT_WRITE
%78 = or i32 %76, %77
%79 = load i32, i32* @MAP_SHARED
%80 = load i32, i32* %7
%81 = call i8* @mmap(i8* null, i64 %75, i32 %78, i32 %79, i32 %80, i32 0)
store i8* %81, i8** %5
%82 = load i8*, i8** %5
%83 = load i8*, i8** @MAP_FAILED
%84 = icmp eq i8* %82, %83
br i1 %84, label %85, label %89
85: ; preds = %74
%86 = load i64, i64* @errno
%87 = call i8* @strerror(i64 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %87)
store i32 2, i32* %1
br label %126
89: ; preds = %74
%90 = load i8*, i8** %5
%91 = load i64, i64* %6
%92 = udiv i64 %91, 2
%93 = load i32, i32* @PROT_READ
%94 = load i32, i32* @MAP_SHARED
%95 = load i32, i32* @MAP_FIXED
%96 = or i32 %94, %95
%97 = load i32, i32* %7
%98 = call i8* @mmap(i8* %90, i64 %92, i32 %93, i32 %96, i32 %97, i32 0)
store i8* %98, i8** %5
%99 = load i8*, i8** %5
%100 = load i8*, i8** @MAP_FAILED
%101 = icmp eq i8* %99, %100
br i1 %101, label %102, label %115
102: ; preds = %89
%103 = load i64, i64* @errno
%104 = load i64, i64* @ENOTSUP
%105 = icmp ne i64 %103, %104
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %114
108: ; preds = %102
%109 = load i64, i64* @errno
%110 = call i8* @strerror(i64 %109)
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %110)
%112 = load i32, i32* %8
%113 = add nsw i32 %112, 1
store i32 %113, i32* %8
br label %114
114: ; preds = %108, %106
br label %120
115: ; preds = %89
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%117 = load i8*, i8** %5
%118 = load i64, i64* %6
%119 = call i32 @munmap(i8* %117, i64 %118)
br label %120
120: ; preds = %115, %114
%121 = load i32, i32* %8
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %124
123: ; preds = %120
store i32 1, i32* %1
br label %126
124: ; preds = %120
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %1
br label %126
126: ; preds = %124, %123, %85, %41, %30
%127 = load i32, i32* %1
ret i32 %127
}

LLVM IR (-O2):
@.str = [22 x i8] c"/tmp/pts_mmap_27_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 i64 0
@.str.2 = [26 x i8] c"Error at ftruncate(): %s\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@ENOTSUP = global i64 0
@.str.4 = [29 x i8] c"MAP_PRIVATE failed with: %s\0A\00"
@MAP_SHARED = global i32 0
@.str.6 = [21 x i8] c"Error at mmap(): %s\0A\00"
@MAP_FIXED = global i32 0
@.str.8 = [27 x i8] c"MAP_FIXED failed with: %s\0A\00"
@str = [22 x i8] c"MAP_PRIVATE succeeded\00"
@str.11 = [20 x i8] c"MAP_FIXED succeeded\00"
@str.12 = [12 x i8] c"Test PASSED\00"
@str.13 = [27 x i8] c"MAP_FIXED is not supported\00"
@str.14 = [29 x i8] c"MAP_PRIVATE is not supported\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getpid()
%4 = call i32 @snprintf(i8* %2, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @unlink(i8* %2)
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_RDWR
%8 = or i32 %7, %6
%9 = load i32, i32* @O_EXCL
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %12, %11
%14 = call i32 @open(i8* %2, i32 %10, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = load i64, i64* @errno
%18 = call i8* @strerror(i64 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %84
20: ; preds = %0
%21 = call i32 @unlink(i8* %2)
%22 = call i32 @ftruncate(i32 %14, i32 1024)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = call i8* @strerror(i64 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %84
28: ; preds = %20
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @PROT_WRITE
%31 = or i32 %30, %29
%32 = load i32, i32* @MAP_PRIVATE
%33 = call i8* @mmap(i8* null, i64 1024, i32 %31, i32 %32, i32 %14, i32 0)
%34 = load i8*, i8** @MAP_FAILED
%35 = icmp eq i8* %33, %34
br i1 %35, label %36, label %45
36: ; preds = %28
%37 = load i64, i64* @errno
%38 = load i64, i64* @ENOTSUP
%39 = icmp eq i64 %37, %38
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.14, i64 0, i64 0))
br label %48
42: ; preds = %36
%43 = call i8* @strerror(i64 %37)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %43)
br label %48
45: ; preds = %28
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%47 = call i32 @munmap(i8* %33, i64 1024)
br label %48
48: ; preds = %40, %42, %45
%49 = phi i1 [ true, %40 ], [ false, %42 ], [ true, %45 ]
%50 = load i32, i32* @PROT_READ
%51 = load i32, i32* @PROT_WRITE
%52 = or i32 %51, %50
%53 = load i32, i32* @MAP_SHARED
%54 = call i8* @mmap(i8* null, i64 1024, i32 %52, i32 %53, i32 %14, i32 0)
%55 = load i8*, i8** @MAP_FAILED
%56 = icmp eq i8* %54, %55
br i1 %56, label %57, label %61
57: ; preds = %48
%58 = load i64, i64* @errno
%59 = call i8* @strerror(i64 %58)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %59)
br label %84
61: ; preds = %48
%62 = load i32, i32* @PROT_READ
%63 = load i32, i32* @MAP_SHARED
%64 = load i32, i32* @MAP_FIXED
%65 = or i32 %64, %63
%66 = call i8* @mmap(i8* %54, i64 512, i32 %62, i32 %65, i32 %14, i32 0)
%67 = load i8*, i8** @MAP_FAILED
%68 = icmp eq i8* %66, %67
br i1 %68, label %69, label %78
69: ; preds = %61
%70 = load i64, i64* @errno
%71 = load i64, i64* @ENOTSUP
%72 = icmp eq i64 %70, %71
br i1 %72, label %75, label %73
73: ; preds = %69
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
br label %81
75: ; preds = %69
%76 = call i8* @strerror(i64 %70)
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %76)
br label %84
78: ; preds = %61
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
%80 = call i32 @munmap(i8* %66, i64 1024)
br label %81
81: ; preds = %73, %78
br i1 %49, label %82, label %84
82: ; preds = %81
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0))
br label %84
84: ; preds = %75, %81, %82, %57, %24, %16
%85 = phi i32 [ 2, %16 ], [ 2, %24 ], [ 2, %57 ], [ 0, %82 ], [ 1, %81 ], [ 1, %75 ]
ret i32 %85
}