#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 uint8_t;
typedef int /*<<< orphan*/ template;
typedef int /*<<< orphan*/ code;

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ftruncate(int, int);
scalar_t__ memcmp(int const *, void *, int);
int /*<<< orphan*/ memcpy(void *, ...);
int mkstemp(char *);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
scalar_t__ munmap(void *, int);
int /*<<< orphan*/ perror_exit(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int stub1();
scalar_t__ unlink(char *);
int main(void) {
  const char template[] = "./mmap-wx-XXXXXX";
  const uint8_t code[] = {0x31, 0xc0, 0xc3};
  char filename[4096];
  int fd, result;
  void *wptr, *xptr;
  memcpy(filename, template, sizeof(template));
  fd = mkstemp(filename);
  if (fd == -1)
    perror_exit("mkstemp");
  if (unlink(filename) < 0)
    perror_exit("unlink");
  if (ftruncate(fd, sizeof(code)) < 0)
    perror_exit("ftruncate");
  wptr = mmap(NULL, sizeof(code), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  if (wptr == MAP_FAILED)
    perror_exit("mmap(RW)");
  xptr = mmap(NULL, sizeof(code), PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0);
  if (xptr == MAP_FAILED)
    perror_exit("mmap(RX)");
  printf("RW+RX mmap succeeded at %p and %p in %s\n", wptr, xptr, filename);
  memcpy(wptr, code, sizeof(code));
  if (memcmp(code, xptr, sizeof(code))) {
    fprintf(stderr, "RW and RX mmaps don't share the same data\n");
    return 1;
  }
  result = ((int (*)(void))(uintptr_t)xptr)();
  if (result != 0) {
    fprintf(stderr, "Unexpected result: %d\n", result);
    return 1;
  } else {
    printf("Code successfully executed\n");
  }
  if (munmap(xptr, sizeof(code)) < 0)
    perror_exit("munmap(RX)");
  if (munmap(wptr, sizeof(code)) < 0)
    perror_exit("munmap(RW)");
  if (close(fd) < 0)
    perror_exit("close");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe37(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe34(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe32(%rip),%al
mov    %al,-0x10(%rbp)
mov    0xe2c(%rip),%rax
mov    %rax,-0x2c(%rbp)
mov    0xe2a(%rip),%eax
mov    %eax,-0x24(%rbp)
lea    -0x1030(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    $0x11,%edx
call   10a0 <memcpy@plt>
lea    -0x1030(%rbp),%rdi
call   10b0 <mkstemp@plt>
mov    %eax,-0x1034(%rbp)
cmpl   $0xffffffff,-0x1034(%rbp)
jne    1237 <main+0x87>
lea    0xdee(%rip),%rdi
call   10d0 <perror_exit@plt>
lea    -0x1030(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1259 <main+0xa9>
lea    0xdd4(%rip),%rdi
call   10d0 <perror_exit@plt>
mov    -0x1034(%rbp),%edi
mov    $0xc,%esi
call   1060 <ftruncate@plt>
cmp    $0x0,%rax
jge    127f <main+0xcf>
lea    0xdb5(%rip),%rdi
call   10d0 <perror_exit@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
mov    0x2d31(%rip),%rax
or     (%rax),%edx
mov    0x2d50(%rip),%rax
mov    (%rax),%ecx
mov    -0x1034(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x1040(%rbp),%rax
mov    0x2cf1(%rip),%rcx
cmp    (%rcx),%rax
jne    12dc <main+0x12c>
lea    0xd62(%rip),%rdi
call   10d0 <perror_exit@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edx
mov    0x2cec(%rip),%rax
or     (%rax),%edx
mov    0x2cf3(%rip),%rax
mov    (%rax),%ecx
mov    -0x1034(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x1048(%rbp)
mov    -0x1048(%rbp),%rax
mov    0x2c94(%rip),%rcx
cmp    (%rcx),%rax
jne    1339 <main+0x189>
lea    0xd0e(%rip),%rdi
call   10d0 <perror_exit@plt>
mov    -0x1040(%rbp),%rsi
mov    -0x1048(%rbp),%rdx
lea    -0x1030(%rbp),%rcx
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1040(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
mov    $0xc,%edx
call   10a0 <memcpy@plt>
lea    -0x2c(%rbp),%rdi
mov    -0x1048(%rbp),%rsi
mov    $0xc,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     13b5 <main+0x205>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    147b <main+0x2cb>
call   *-0x1048(%rbp)
mov    %eax,-0x1038(%rbp)
cmpl   $0x0,-0x1038(%rbp)
je     13f7 <main+0x247>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    -0x1038(%rbp),%edx
lea    0xcbb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    147b <main+0x2cb>
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1048(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <munmap@plt>
cmp    $0x0,%rax
jge    142c <main+0x27c>
lea    0xcab(%rip),%rdi
call   10d0 <perror_exit@plt>
mov    -0x1040(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <munmap@plt>
cmp    $0x0,%rax
jge    1453 <main+0x2a3>
lea    0xc8f(%rip),%rdi
call   10d0 <perror_exit@plt>
mov    -0x1034(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jge    1474 <main+0x2c4>
lea    0xc79(%rip),%rdi
call   10d0 <perror_exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1030,%rsp
movaps 0xe2a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
mov    0xe36(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xe23(%rip),%rax
mov    %rax,(%rsp)
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    $0x11,%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   10b0 <memcpy@plt>
mov    %rbx,%rdi
call   10c0 <mkstemp@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    122a <main+0x6a>
lea    0xdfb(%rip),%rdi
call   10e0 <perror_exit@plt>
lea    0x30(%rsp),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    1245 <main+0x85>
lea    0xde8(%rip),%rdi
call   10e0 <perror_exit@plt>
mov    %r14d,%edi
mov    $0xc,%esi
call   1070 <ftruncate@plt>
test   %rax,%rax
jns    1263 <main+0xa3>
lea    0xdd1(%rip),%rdi
call   10e0 <perror_exit@plt>
mov    0x2d8e(%rip),%r12
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
or     (%r12),%edx
mov    0x2d6a(%rip),%rbp
mov    0x0(%rbp),%ecx
xor    %edi,%edi
mov    $0xc,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%r15
mov    0x2d1b(%rip),%rbx
cmp    (%rbx),%rax
jne    12ae <main+0xee>
lea    0xd90(%rip),%rdi
call   10e0 <perror_exit@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
or     (%r12),%edx
mov    0x0(%rbp),%ecx
xor    %edi,%edi
mov    $0xc,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
cmp    (%rbx),%rax
jne    12e4 <main+0x124>
lea    0xd63(%rip),%rdi
call   10e0 <perror_exit@plt>
lea    0xd60(%rip),%rdi
lea    0x30(%rsp),%rcx
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rbx
mov    $0xc,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <memcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     1348 <main+0x188>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebx
jmp    13d1 <main+0x211>
call   *%rbp
test   %eax,%eax
je     136e <main+0x1ae>
mov    0x2c73(%rip),%rcx
mov    (%rcx),%edi
lea    0xd41(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebx
jmp    13d1 <main+0x211>
lea    0xd5d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
mov    $0xc,%esi
call   10d0 <munmap@plt>
test   %rax,%rax
jns    1398 <main+0x1d8>
lea    0xd23(%rip),%rdi
call   10e0 <perror_exit@plt>
mov    %r15,%rdi
mov    $0xc,%esi
call   10d0 <munmap@plt>
test   %rax,%rax
jns    13b6 <main+0x1f6>
lea    0xd10(%rip),%rdi
call   10e0 <perror_exit@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    13d1 <main+0x211>
lea    0xd00(%rip),%rdi
call   10e0 <perror_exit@plt>
mov    %ebx,%eax
add    $0x1030,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.template = [17 x i8] c"./mmap-wx-XXXXXX\00"
@__const.main.code = [3 x i32] [i32 49, i32 192, i32 195]
@.str = [8 x i8] c"mkstemp\00"
@.str.1 = [7 x i8] c"unlink\00"
@.str.2 = [10 x i8] c"ftruncate\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [9 x i8] c"mmap(RW)\00"
@PROT_EXEC = global i32 0
@.str.4 = [9 x i8] c"mmap(RX)\00"
@.str.5 = [41 x i8] c"RW+RX mmap succeeded at %p and %p in %s\0A\00"
@stderr = global i32 0
@.str.6 = [43 x i8] c"RW and RX mmaps don't share the same data\0A\00"
@.str.7 = [23 x i8] c"Unexpected result: %d\0A\00"
@.str.8 = [28 x i8] c"Code successfully executed\0A\00"
@.str.9 = [11 x i8] c"munmap(RX)\00"
@.str.10 = [11 x i8] c"munmap(RW)\00"
@.str.11 = [6 x i8] c"close\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca [3 x i32]
%4 = alloca [4096 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %1
%9 = bitcast [17 x i8]* %2 to i8*
%10 = bitcast [3 x i32]* %3 to i8*
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @memcpy(i8* %11, i8* %12, i64 17)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%15 = call i32 @mkstemp(i8* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @perror_exit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %0
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%22 = call i64 @unlink(i8* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @perror_exit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* %5
%28 = call i64 @ftruncate(i32 %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @PROT_WRITE
%35 = or i32 %33, %34
%36 = load i32, i32* @MAP_SHARED
%37 = load i32, i32* %5
%38 = call i8* @mmap(i32* null, i32 12, i32 %35, i32 %36, i32 %37, i32 0)
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = load i8*, i8** @MAP_FAILED
%41 = icmp eq i8* %39, %40
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 @perror_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %32
%45 = load i32, i32* @PROT_READ
%46 = load i32, i32* @PROT_EXEC
%47 = or i32 %45, %46
%48 = load i32, i32* @MAP_SHARED
%49 = load i32, i32* %5
%50 = call i8* @mmap(i32* null, i32 12, i32 %47, i32 %48, i32 %49, i32 0)
store i8* %50, i8** %8
%51 = load i8*, i8** %8
%52 = load i8*, i8** @MAP_FAILED
%53 = icmp eq i8* %51, %52
br i1 %53, label %54, label %56
54: ; preds = %44
%55 = call i32 @perror_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %44
%57 = load i8*, i8** %7
%58 = load i8*, i8** %8
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %57, i8* %58, i8* %59)
%61 = load i8*, i8** %7
%62 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%63 = call i32 (i8*, ...) @memcpy(i8* %61, i32* %62, i64 12)
%64 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%65 = load i8*, i8** %8
%66 = call i64 @memcmp(i32* %64, i8* %65, i32 12)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %56
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %103
71: ; preds = %56
%72 = load i8*, i8** %8
%73 = ptrtoint i8* %72 to i64
%74 = inttoptr i64 %73 to i32 ()*
%75 = call i32 %74()
store i32 %75, i32* %6
%76 = load i32, i32* %6
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %71
%79 = load i32, i32* @stderr
%80 = load i32, i32* %6
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %80)
store i32 1, i32* %1
br label %103
82: ; preds = %71
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %84
84: ; preds = %82
%85 = load i8*, i8** %8
%86 = call i64 @munmap(i8* %85, i32 12)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %84
%89 = call i32 @perror_exit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %90
90: ; preds = %88, %84
%91 = load i8*, i8** %7
%92 = call i64 @munmap(i8* %91, i32 12)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 @perror_exit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %96
96: ; preds = %94, %90
%97 = load i32, i32* %5
%98 = call i64 @close(i32 %97)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %96
%101 = call i32 @perror_exit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %102
102: ; preds = %100, %96
store i32 0, i32* %1
br label %103
103: ; preds = %102, %78, %68
%104 = load i32, i32* %1
ret i32 %104
}

LLVM IR (-O2):
@__const.main.template = [17 x i8] c"./mmap-wx-XXXXXX\00"
@__const.main.code = [3 x i32] [i32 49, i32 192, i32 195]
@.str = [8 x i8] c"mkstemp\00"
@.str.1 = [7 x i8] c"unlink\00"
@.str.2 = [10 x i8] c"ftruncate\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.3 = [9 x i8] c"mmap(RW)\00"
@PROT_EXEC = global i32 0
@.str.4 = [9 x i8] c"mmap(RX)\00"
@.str.5 = [41 x i8] c"RW+RX mmap succeeded at %p and %p in %s\0A\00"
@stderr = global i32 0
@.str.6 = [43 x i8] c"RW and RX mmaps don't share the same data\0A\00"
@.str.7 = [23 x i8] c"Unexpected result: %d\0A\00"
@.str.9 = [11 x i8] c"munmap(RX)\00"
@.str.10 = [11 x i8] c"munmap(RW)\00"
@.str.11 = [6 x i8] c"close\00"
@str = [27 x i8] c"Code successfully executed\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = alloca [3 x i32]
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%5 = bitcast [3 x i32]* %2 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, ...) @memcpy(i8* %6, i8* %4, i64 17)
%8 = call i32 @mkstemp(i8* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror_exit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i64 @unlink(i8* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror_exit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = call i64 @ftruncate(i32 %8, i32 12)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @perror_exit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @PROT_WRITE
%25 = or i32 %24, %23
%26 = load i32, i32* @MAP_SHARED
%27 = call i8* @mmap(i32* null, i32 12, i32 %25, i32 %26, i32 %8, i32 0)
%28 = load i8*, i8** @MAP_FAILED
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 @perror_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %22
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @PROT_EXEC
%35 = or i32 %34, %33
%36 = load i32, i32* @MAP_SHARED
%37 = call i8* @mmap(i32* null, i32 12, i32 %35, i32 %36, i32 %8, i32 0)
%38 = load i8*, i8** @MAP_FAILED
%39 = icmp eq i8* %37, %38
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @perror_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %27, i8* %37, i8* %6)
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%45 = call i32 (i8*, ...) @memcpy(i8* %27, i32* %44, i64 12)
%46 = call i64 @memcmp(i32* %44, i8* %37, i32 12)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
br label %74
51: ; preds = %42
%52 = bitcast i8* %37 to i32 ()*
%53 = call i32 %52()
%54 = icmp eq i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %53)
br label %74
58: ; preds = %51
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%60 = call i64 @munmap(i8* %37, i32 12)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 @perror_exit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %64
64: ; preds = %62, %58
%65 = call i64 @munmap(i8* %27, i32 12)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @perror_exit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = call i64 @close(i32 %8)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 @perror_exit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %74
74: ; preds = %69, %72, %55, %48
%75 = phi i32 [ 1, %48 ], [ 1, %55 ], [ 0, %72 ], [ 0, %69 ]
ret i32 %75
}