#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;
void *MAP_FAILED;
int MAP_FIXED;
int MAP_NORESERVE;
int MAP_PRIVATE;
int /*<<< orphan*/ PROT_NONE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *mmap64(void *, size_t, int /*<<< orphan*/, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void safe_zero_mmap(void *addr, size_t size) {
  void *ret_addr =
      mmap64(addr, size, PROT_NONE,
             MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_NORESERVE, -1, 0);
  if (ret_addr == MAP_FAILED) {
    perror("MMAP_WRAPPER(zero)");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<safe_zero_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    0x2e68(%rip),%rax
mov    (%rax),%ecx
mov    0x2e77(%rip),%rax
or     (%rax),%ecx
mov    0x2e4e(%rip),%rax
or     (%rax),%ecx
mov    0x2e6d(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap64@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
jne    11b5 <safe_zero_mmap+0x85>
lea    0xe5e(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_zero_mmap>:
push   %rax
mov    0x2e88(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2ea6(%rip),%rax
mov    0x2e67(%rip),%rdx
or     (%rdx),%ecx
mov    (%rax),%edx
mov    0x2e84(%rip),%rax
or     (%rax),%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap64@plt>
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
je     117a <safe_zero_mmap+0x4a>
pop    %rax
ret
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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