#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 */
scalar_t__ EINVAL;
int MAP_ANON;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
void mmap_bad(void) {
  void *addr;
  addr = mmap(((void *)0x7fff0000), (0x20000), PROT_READ | PROT_WRITE,
              MAP_ANON | MAP_PRIVATE, -1, 0);
  assert(addr == MAP_FAILED);
  assert(errno == EINVAL);
  addr = mmap(((void *)0x3ff000), (0x1000), PROT_READ | PROT_WRITE,
              MAP_ANON | MAP_PRIVATE, -1, 0);
  assert(addr == MAP_FAILED);
  assert(errno == EINVAL);
  addr = mmap(((void *)0x12345678), (0x1000), PROT_READ | PROT_WRITE,
              MAP_ANON | MAP_PRIVATE, -1, 0);
  assert(addr == MAP_FAILED);
  assert(errno == EINVAL);
}


x86 assembly (clang, -O0):
<mmap_bad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edx
mov    0x2e98(%rip),%rax
or     (%rax),%edx
mov    0x2e7f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6e(%rip),%rax
or     (%rax),%ecx
mov    $0x7fff0000,%edi
mov    $0x20000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
mov    0x2e1c(%rip),%rax
or     (%rax),%edx
mov    0x2e03(%rip),%rax
mov    (%rax),%ecx
mov    0x2df2(%rip),%rax
or     (%rax),%ecx
mov    $0x3ff000,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rax
mov    0x2db8(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
mov    0x2da0(%rip),%rax
or     (%rax),%edx
mov    0x2d87(%rip),%rax
mov    (%rax),%ecx
mov    0x2d76(%rip),%rax
or     (%rax),%ecx
mov    $0x12345678,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%rax
mov    0x2d3c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_bad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ec6(%rip),%rax
mov    0x2e97(%rip),%r13
mov    0x0(%r13),%edx
or     (%rax),%edx
mov    0x2e7a(%rip),%r12
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%ecx
or     (%r12),%ecx
mov    $0x7fff0000,%edi
mov    $0x20000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e3e(%rip),%r14
xor    %edi,%edi
cmp    (%r14),%rax
sete   %dil
call   1040 <assert@plt>
mov    0x2e51(%rip),%r15
mov    (%r15),%rax
mov    0x2e37(%rip),%rbp
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13),%edx
mov    0x2e4d(%rip),%rax
or     (%rax),%edx
mov    (%rbx),%ecx
or     (%r12),%ecx
mov    $0x3ff000,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
xor    %edi,%edi
cmp    (%r14),%rax
sete   %dil
call   1040 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
call   1040 <assert@plt>
mov    0x0(%r13),%edx
mov    0x2e02(%rip),%rax
or     (%rax),%edx
mov    (%rbx),%ecx
or     (%r12),%ecx
mov    $0x12345678,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
xor    %edi,%edi
cmp    (%r14),%rax
sete   %dil
call   1040 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
cmp    0x0(%rbp),%rax
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <assert@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@errno = global i64 0
@EINVAL = global i64 0
define void @mmap_bad() {
%1 = alloca i8*
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %2, %3
%5 = load i32, i32* @MAP_ANON
%6 = load i32, i32* @MAP_PRIVATE
%7 = or i32 %5, %6
%8 = call i8* @mmap(i8* inttoptr (i64 2147418112 to i8*), i32 131072, i32 %4, i32 %7, i32 -1, i32 0)
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = load i8*, i8** @MAP_FAILED
%11 = icmp eq i8* %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp eq i64 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @PROT_WRITE
%21 = or i32 %19, %20
%22 = load i32, i32* @MAP_ANON
%23 = load i32, i32* @MAP_PRIVATE
%24 = or i32 %22, %23
%25 = call i8* @mmap(i8* inttoptr (i64 4190208 to i8*), i32 4096, i32 %21, i32 %24, i32 -1, i32 0)
store i8* %25, i8** %1
%26 = load i8*, i8** %1
%27 = load i8*, i8** @MAP_FAILED
%28 = icmp eq i8* %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINVAL
%33 = icmp eq i64 %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* @PROT_READ
%37 = load i32, i32* @PROT_WRITE
%38 = or i32 %36, %37
%39 = load i32, i32* @MAP_ANON
%40 = load i32, i32* @MAP_PRIVATE
%41 = or i32 %39, %40
%42 = call i8* @mmap(i8* inttoptr (i64 305419896 to i8*), i32 4096, i32 %38, i32 %41, i32 -1, i32 0)
store i8* %42, i8** %1
%43 = load i8*, i8** %1
%44 = load i8*, i8** @MAP_FAILED
%45 = icmp eq i8* %43, %44
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i64, i64* @errno
%49 = load i64, i64* @EINVAL
%50 = icmp eq i64 %48, %49
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@errno = global i64 0
@EINVAL = global i64 0
define void @mmap_bad() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_ANON
%5 = load i32, i32* @MAP_PRIVATE
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i8* inttoptr (i64 2147418112 to i8*), i32 131072, i32 %3, i32 %6, i32 -1, i32 0)
%8 = load i8*, i8** @MAP_FAILED
%9 = icmp eq i8* %7, %8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINVAL
%14 = icmp eq i64 %12, %13
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = load i32, i32* @PROT_READ
%18 = load i32, i32* @PROT_WRITE
%19 = or i32 %18, %17
%20 = load i32, i32* @MAP_ANON
%21 = load i32, i32* @MAP_PRIVATE
%22 = or i32 %21, %20
%23 = tail call i8* @mmap(i8* inttoptr (i64 4190208 to i8*), i32 4096, i32 %19, i32 %22, i32 -1, i32 0)
%24 = load i8*, i8** @MAP_FAILED
%25 = icmp eq i8* %23, %24
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = load i64, i64* @errno
%29 = load i64, i64* @EINVAL
%30 = icmp eq i64 %28, %29
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @PROT_WRITE
%35 = or i32 %34, %33
%36 = load i32, i32* @MAP_ANON
%37 = load i32, i32* @MAP_PRIVATE
%38 = or i32 %37, %36
%39 = tail call i8* @mmap(i8* inttoptr (i64 305419896 to i8*), i32 4096, i32 %35, i32 %38, i32 -1, i32 0)
%40 = load i8*, i8** @MAP_FAILED
%41 = icmp eq i8* %39, %40
%42 = zext i1 %41 to i32
%43 = tail call i32 @assert(i32 %42)
%44 = load i64, i64* @errno
%45 = load i64, i64* @EINVAL
%46 = icmp eq i64 %44, %45
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
ret void
}