#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;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
void *mmap(int /*<<< orphan*/ *, unsigned long, int, int, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void *mmap_memory(unsigned long size) {
  void *mmap_pointer;
  mmap_pointer = mmap(NULL, size, PROT_READ | PROT_WRITE,
                      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  if ((!mmap_pointer) && (mmap_pointer != MAP_FAILED)) {
    perror("mmap");
    exit(-1);
  }
  return mmap_pointer;
}


x86 assembly (clang, -O0):
<mmap_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
mov    0x2e80(%rip),%rax
or     (%rax),%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11af <mmap_memory+0x7f>
mov    -0x10(%rbp),%rax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
je     11af <mmap_memory+0x7f>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_memory>:
push   %rax
mov    %rdi,%rsi
mov    0x2ebd(%rip),%rax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7b(%rip),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %rax,%rax
jne    117a <mmap_memory+0x4a>
mov    0x2e4c(%rip),%rcx
cmpq   $0x0,(%rcx)
jne    117c <mmap_memory+0x4c>
pop    %rcx
ret
lea    0xe7d(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i8* @mmap_memory(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = or i32 %8, %9
%11 = call i8* @mmap(i32* null, i64 %4, i32 %7, i32 %10, i32 -1, i32 0)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %21, label %14
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i8*, i8** @MAP_FAILED
%17 = icmp ne i8* %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %14, %1
%22 = load i8*, i8** %3
ret i8* %22
}

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