#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;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ must_fail(char *, int);
void *must_mmap(int size, int prot, int flags) {
  if (prot == 0)
    prot = PROT_READ | PROT_WRITE;
  if (flags == 0)
    flags = MAP_PRIVATE | MAP_ANONYMOUS;
  void *mem = mmap(NULL, size, prot, flags, -1, 0);
  if (!mem)
    must_fail("mmap", size);
  return mem;
}


x86 assembly (clang, -O0):
<must_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1150 <must_mmap+0x30>
mov    0x2eb6(%rip),%rax
mov    (%rax),%eax
mov    0x2e85(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116f <must_mmap+0x4f>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    0x2e76(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <must_mmap+0x88>
mov    -0x4(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1030 <must_fail@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<must_mmap>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ece(%rip),%rcx
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
test   %esi,%esi
cmovne %esi,%eax
mov    0x2e87(%rip),%rsi
mov    0x2e98(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
mov    %edi,%ebp
test   %edx,%edx
cmovne %edx,%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    %eax,%edx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117d <must_mmap+0x5d>
lea    0xe8a(%rip),%rdi
mov    %ebp,%esi
call   1030 <must_fail@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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