#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 PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ check_bytes(void *);
int /*<<< orphan*/ exit(int);
void *mmap(void *, unsigned long, int, int, int /*<<< orphan*/,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, unsigned long);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, void *);
int /*<<< orphan*/ read_bytes(void *);
int /*<<< orphan*/ write_bytes(void *);
int main(void) {
  void *addr;
  addr = mmap((void *)(0x0UL), (256UL * 1024 * 1024), (PROT_READ | PROT_WRITE),
              (MAP_PRIVATE | MAP_ANONYMOUS | 0x40), 0, 0);
  if (addr == MAP_FAILED) {
    perror("mmap");
    exit(1);
  }
  printf("Returned address is %p\n", addr);
  check_bytes(addr);
  write_bytes(addr);
  read_bytes(addr);
  munmap(addr, (256UL * 1024 * 1024));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    0x2e31(%rip),%rax
or     (%rax),%edx
mov    0x2e20(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2f(%rip),%rax
or     (%rax),%ecx
or     $0x40,%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x10000000,%esi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1040 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%rax
jne    11f8 <main+0x78>
lea    0xe17(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <check_bytes@plt>
mov    -0x10(%rbp),%rdi
call   1060 <write_bytes@plt>
mov    -0x10(%rbp),%rdi
call   1030 <read_bytes@plt>
mov    -0x10(%rbp),%rdi
mov    $0x10000000,%esi
call   1070 <munmap@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    0x2e41(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3d(%rip),%rax
or     (%rax),%ecx
or     $0x40,%ecx
mov    $0x10000000,%esi
xor    %edi,%edi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2dfc(%rip),%rax
cmp    (%rax),%rbx
je     1201 <main+0x81>
lea    0xe35(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <check_bytes@plt>
mov    %rbx,%rdi
call   1060 <write_bytes@plt>
mov    %rbx,%rdi
call   1030 <read_bytes@plt>
mov    $0x10000000,%esi
mov    %rbx,%rdi
call   1070 <munmap@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xdf8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [24 x i8] c"Returned address is %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_PRIVATE
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = or i32 %6, %7
%9 = or i32 %8, 64
%10 = call i8* @mmap(i8* null, i64 268435456, i32 %5, i32 %9, i32 0, i32 0)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %2
%21 = call i32 @check_bytes(i8* %20)
%22 = load i8*, i8** %2
%23 = call i32 @write_bytes(i8* %22)
%24 = load i8*, i8** %2
%25 = call i32 @read_bytes(i8* %24)
%26 = load i8*, i8** %2
%27 = call i32 @munmap(i8* %26, i64 268435456)
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [24 x i8] c"Returned address is %p\0A\00"
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = or i32 %4, %5
%7 = or i32 %6, 64
%8 = tail call i8* @mmap(i8* null, i64 268435456, i32 %3, i32 %7, i32 0, i32 0)
%9 = load i8*, i8** @MAP_FAILED
%10 = icmp eq i8* %8, %9
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%16 = tail call i32 @check_bytes(i8* %8)
%17 = tail call i32 @write_bytes(i8* %8)
%18 = tail call i32 @read_bytes(i8* %8)
%19 = tail call i32 @munmap(i8* %8, i64 268435456)
ret i32 0
}