#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;
int /*<<< orphan*/ err(int, char *);
char *mmap(char *, size_t, int, int, int, int /*<<< orphan*/);
void map_or_die(char *addr, size_t sz) {
  if (mmap(addr, sz, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1,
           0) != addr) {
    err(1, "mmap");
  }
}


x86 assembly (clang, -O0):
<map_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2eb9(%rip),%rax
mov    (%rax),%edx
mov    0x2e88(%rip),%rax
or     (%rax),%edx
mov    0x2e8f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6e(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    -0x8(%rbp),%rax
je     1185 <map_or_die+0x65>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
call   1040 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_or_die>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ecd(%rip),%rax
mov    0x2e9e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2ea3(%rip),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    %rbx,%rax
je     116d <map_or_die+0x4d>
lea    0xe9e(%rip),%rsi
mov    $0x1,%edi
pop    %rbx
jmp    1040 <err@plt>
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@.str = [5 x i8] c"mmap\00"
define void @map_or_die(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i8*, i8** %3
%6 = load i64, i64* %4
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_ANONYMOUS
%11 = load i32, i32* @MAP_PRIVATE
%12 = or i32 %10, %11
%13 = call i8* @mmap(i8* %5, i64 %6, i32 %9, i32 %12, i32 -1, i32 0)
%14 = load i8*, i8** %3
%15 = icmp ne i8* %13, %14
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
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
@.str = [5 x i8] c"mmap\00"
define void @map_or_die(i8* %0, i64 %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = load i32, i32* @MAP_PRIVATE
%8 = or i32 %7, %6
%9 = tail call i8* @mmap(i8* %0, i64 %1, i32 %5, i32 %8, i32 -1, i32 0)
%10 = icmp eq i8* %9, %0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
ret void
}