#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 /*<<< orphan*/ PROT_NONE;
int /*<<< orphan*/ assert(int);
int getpagesize();
void *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int, int,
           int /*<<< orphan*/);
int munmap(void *, int);
void *make_invalid_ptr(void) {
  int page_size, ans;
  void *ptr;
  page_size = getpagesize();
  ptr = mmap(0, page_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  assert(ptr != MAP_FAILED);
  ans = munmap(ptr, page_size);
  assert(ans == 0);
  return ptr;
}


x86 assembly (clang, -O0):
<make_invalid_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
mov    0x2e6b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e72(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <munmap@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_invalid_ptr>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <getpagesize@plt>
mov    %eax,%ebp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
mov    0x2e74(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %ebp,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e45(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%rbx
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <munmap@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PROT_NONE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
define i8* @make_invalid_ptr() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 (...) @getpagesize()
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = load i32, i32* @PROT_NONE
%7 = load i32, i32* @MAP_PRIVATE
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = or i32 %7, %8
%10 = call i8* @mmap(i32 0, i32 %5, i32 %6, i32 %9, i32 -1, i32 0)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp ne i8* %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %3
%17 = load i32, i32* %1
%18 = call i32 @munmap(i8* %16, i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@PROT_NONE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
define i8* @make_invalid_ptr() {
%1 = tail call i32 (...) @getpagesize()
%2 = load i32, i32* @PROT_NONE
%3 = load i32, i32* @MAP_PRIVATE
%4 = load i32, i32* @MAP_ANONYMOUS
%5 = or i32 %4, %3
%6 = tail call i8* @mmap(i32 0, i32 %1, i32 %2, i32 %5, i32 -1, i32 0)
%7 = load i8*, i8** @MAP_FAILED
%8 = icmp ne i8* %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @munmap(i8* %6, i32 %1)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
ret i8* %6
}