#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();
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];
  int total_size = 1024;
  void *pa;
  size_t len = total_size;
  int fd, err = 0;
  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,-0x114(%rbp)
movslq -0x114(%rbp),%rax
mov    %rax,-0x128(%rbp)
movl   $0x0,-0x130(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xe12(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2dba(%rip),%rax
or     (%rax),%esi
mov    0x2d91(%rip),%rax
or     (%rax),%esi
mov    0x2d70(%rip),%rax
mov    (%rax),%edx
mov    0x2d8f(%rip),%rax
or     (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0xffffffff,-0x12c(%rbp)
jne    1277 <main+0xe7>
mov    0x2d56(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1527 <main+0x397>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x12c(%rbp),%edi
mov    -0x114(%rbp),%esi
call   1080 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    12c9 <main+0x139>
mov    0x2d04(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1527 <main+0x397>
mov    -0x128(%rbp),%rsi
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
mov    0x2cc0(%rip),%rax
or     (%rax),%edx
mov    0x2ca7(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2c6d(%rip),%rcx
cmp    (%rcx),%rax
jne    137d <main+0x1ed>
mov    0x2c85(%rip),%rax
mov    (%rax),%rax
mov    0x2c9b(%rip),%rcx
cmp    (%rcx),%rax
je     1349 <main+0x1b9>
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1378 <main+0x1e8>
mov    0x2c58(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
jmp    139e <main+0x20e>
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1090 <munmap@plt>
mov    -0x128(%rbp),%rsi
mov    0x2c44(%rip),%rax
mov    (%rax),%edx
mov    0x2beb(%rip),%rax
or     (%rax),%edx
mov    0x2c22(%rip),%rax
mov    (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2b98(%rip),%rcx
cmp    (%rcx),%rax
jne    141d <main+0x28d>
mov    0x2bb0(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1527 <main+0x397>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
shr    $0x1,%rsi
mov    0x2bba(%rip),%rax
mov    (%rax),%edx
mov    0x2ba1(%rip),%rax
mov    (%rax),%ecx
mov    0x2b40(%rip),%rax
or     (%rax),%ecx
mov    -0x12c(%rbp),%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
mov    0x2b12(%rip),%rcx
cmp    (%rcx),%rax
jne    14d8 <main+0x348>
mov    0x2b2a(%rip),%rax
mov    (%rax),%rax
mov    0x2b40(%rip),%rcx
cmp    (%rcx),%rax
je     14a4 <main+0x314>
lea    0xc14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14d3 <main+0x343>
mov    0x2afd(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xc0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
jmp    14f9 <main+0x369>
lea    0xc04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
call   1090 <munmap@plt>
cmpl   $0x0,-0x130(%rbp)
je     1512 <main+0x382>
movl   $0x1,-0x4(%rbp)
jmp    1527 <main+0x397>
lea    0xbdf(%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 i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 1024, i32* %3
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
store i64 %9, i64* %5
store i32 0, i32* %7
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i32 (...) @getpid()
%12 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = call i32 @unlink(i8* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_RDWR
%18 = or i32 %16, %17
%19 = load i32, i32* @O_EXCL
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %15, i32 %20, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %0
%28 = load i64, i64* @errno
%29 = call i8* @strerror(i64 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 2, i32* %1
br label %123
31: ; preds = %0
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%33 = call i32 @unlink(i8* %32)
%34 = load i32, i32* %6
%35 = load i32, i32* %3
%36 = call i32 @ftruncate(i32 %34, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i64, i64* @errno
%40 = call i8* @strerror(i64 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %40)
store i32 2, i32* %1
br label %123
42: ; preds = %31
%43 = load i64, i64* %5
%44 = load i32, i32* @PROT_READ
%45 = load i32, i32* @PROT_WRITE
%46 = or i32 %44, %45
%47 = load i32, i32* @MAP_PRIVATE
%48 = load i32, i32* %6
%49 = call i8* @mmap(i8* null, i64 %43, i32 %46, i32 %47, i32 %48, i32 0)
store i8* %49, i8** %4
%50 = load i8*, i8** %4
%51 = load i8*, i8** @MAP_FAILED
%52 = icmp eq i8* %50, %51
br i1 %52, label %53, label %66
53: ; preds = %42
%54 = load i64, i64* @errno
%55 = load i64, i64* @ENOTSUP
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %65
59: ; preds = %53
%60 = load i64, i64* @errno
%61 = call i8* @strerror(i64 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %65
65: ; preds = %59, %57
br label %71
66: ; preds = %42
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%68 = load i8*, i8** %4
%69 = load i64, i64* %5
%70 = call i32 @munmap(i8* %68, i64 %69)
br label %71
71: ; preds = %66, %65
%72 = load i64, i64* %5
%73 = load i32, i32* @PROT_READ
%74 = load i32, i32* @PROT_WRITE
%75 = or i32 %73, %74
%76 = load i32, i32* @MAP_SHARED
%77 = load i32, i32* %6
%78 = call i8* @mmap(i8* null, i64 %72, i32 %75, i32 %76, i32 %77, i32 0)
store i8* %78, i8** %4
%79 = load i8*, i8** %4
%80 = load i8*, i8** @MAP_FAILED
%81 = icmp eq i8* %79, %80
br i1 %81, label %82, label %86
82: ; preds = %71
%83 = load i64, i64* @errno
%84 = call i8* @strerror(i64 %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %84)
store i32 2, i32* %1
br label %123
86: ; preds = %71
%87 = load i8*, i8** %4
%88 = load i64, i64* %5
%89 = udiv i64 %88, 2
%90 = load i32, i32* @PROT_READ
%91 = load i32, i32* @MAP_SHARED
%92 = load i32, i32* @MAP_FIXED
%93 = or i32 %91, %92
%94 = load i32, i32* %6
%95 = call i8* @mmap(i8* %87, i64 %89, i32 %90, i32 %93, i32 %94, i32 0)
store i8* %95, i8** %4
%96 = load i8*, i8** %4
%97 = load i8*, i8** @MAP_FAILED
%98 = icmp eq i8* %96, %97
br i1 %98, label %99, label %112
99: ; preds = %86
%100 = load i64, i64* @errno
%101 = load i64, i64* @ENOTSUP
%102 = icmp ne i64 %100, %101
br i1 %102, label %103, label %105
103: ; preds = %99
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %111
105: ; preds = %99
%106 = load i64, i64* @errno
%107 = call i8* @strerror(i64 %106)
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %107)
%109 = load i32, i32* %7
%110 = add nsw i32 %109, 1
store i32 %110, i32* %7
br label %111
111: ; preds = %105, %103
br label %117
112: ; preds = %86
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%114 = load i8*, i8** %4
%115 = load i64, i64* %5
%116 = call i32 @munmap(i8* %114, i64 %115)
br label %117
117: ; preds = %112, %111
%118 = load i32, i32* %7
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %121
120: ; preds = %117
store i32 1, i32* %1
br label %123
121: ; preds = %117
%122 = 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 %123
123: ; preds = %121, %120, %82, %38, %27
%124 = load i32, i32* %1
ret i32 %124
}

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
}