#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 /*<<< orphan*/ EXIT_FAILURE;
int MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/ *, size_t, int, int, int,
                int /*<<< orphan*/);
int munmap(char *, size_t);
int /*<<< orphan*/ perror(char *);
void mmapAlloc() {
  size_t mmapLen = 8;
  char *ptr = (char *)mmap(NULL, mmapLen, PROT_READ | PROT_WRITE,
                           MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  if (ptr == MAP_FAILED) {
    perror("mmap");
    exit(EXIT_FAILURE);
  }
  if (munmap(ptr, mmapLen) == -1) {
    perror("munmap");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<mmapAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x8,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
mov    0x2e64(%rip),%rax
or     (%rax),%edx
mov    0x2e73(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4a(%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)
mov    -0x10(%rbp),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jne    11bc <mmapAlloc+0x7c>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <munmap@plt>
cmp    $0xffffffff,%eax
jne    11ec <mmapAlloc+0xac>
lea    0xe2c(%rip),%rdi
call   1050 <perror@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmapAlloc>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    $0x8,%esi
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e37(%rip),%rcx
cmp    %rax,(%rcx)
je     119a <mmapAlloc+0x5a>
mov    $0x8,%esi
mov    %rax,%rdi
call   1040 <munmap@plt>
cmp    $0xffffffff,%eax
je     11a3 <mmapAlloc+0x63>
pop    %rax
ret
lea    0xe5f(%rip),%rdi
jmp    11aa <mmapAlloc+0x6a>
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

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