#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 */

/* Variables and functions */
int MAP_ANONYMOUS;
scalar_t__ MAP_FAILED;
int MAP_PRIVATE;
int PROT_EXEC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ errno;
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
void doit() {
  size_t m = (size_t)mmap(NULL, 4096, PROT_READ | PROT_WRITE | PROT_EXEC,
                          MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if (m == (size_t)MAP_FAILED)
    printf("%s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edx
mov    0x2e78(%rip),%rax
or     (%rax),%edx
mov    0x2e87(%rip),%rax
or     (%rax),%edx
mov    0x2e5e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7d(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%rax
jne    11b1 <doit+0x81>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e8e(%rip),%rax
or     (%rax),%edx
mov    0x2e65(%rip),%rax
mov    0x2e86(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%rax
jne    119d <doit+0x6d>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
pop    %rax
jmp    1040 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i64 0
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define void @doit() {
%1 = alloca i64
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %2, %3
%5 = load i32, i32* @PROT_EXEC
%6 = or i32 %4, %5
%7 = load i32, i32* @MAP_PRIVATE
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = or i32 %7, %8
%10 = call i64 @mmap(i32* null, i32 4096, i32 %6, i32 %9, i32 -1, i32 0)
store i64 %10, i64* %1
%11 = load i64, i64* %1
%12 = load i64, i64* @MAP_FAILED
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14, %0
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@PROT_EXEC = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i64 0
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define void @doit() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @PROT_EXEC
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = or i32 %7, %6
%9 = tail call i64 @mmap(i32* null, i32 4096, i32 %5, i32 %8, i32 -1, i32 0)
%10 = load i64, i64* @MAP_FAILED
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %12, %0
ret void
}