#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 */
typedef scalar_t__ addr;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int MAP_ANON;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
int munmap(void *, size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
size_t sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  void *addr;
  size_t len = sysconf(_SC_PAGESIZE);
  int protection = PROT_READ | PROT_WRITE;
  int flags = MAP_PRIVATE | MAP_ANON;
  if ((addr = mmap(NULL, len, protection, flags, -1, 0)) == MAP_FAILED) {
    fprintf(stderr, "Err.(%d) mmap(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  char *start_memaddr = (char *)addr;
  char *end_memaddr = (char *)(addr) + 4095;
  *start_memaddr = 10;
  *end_memaddr = 20;
  printf("       Allocated Memory: %d Kb\n", len);
  printf("Allocated Memory starts: %p - Val: %d\n", &(*start_memaddr),
         *start_memaddr);
  printf("  Allocated Memory ends: %p - Val: %d\n", &(*end_memaddr),
         *end_memaddr);
  if (munmap(addr, len) == -1) {
    fprintf(stderr, "Err.(%d) munmap(): %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    0x2e10(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    0x2df3(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    123b <main+0xcb>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xdd8(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0xfff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x14,(%rax)
mov    -0x20(%rbp),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x30(%rbp),%rax
movsbl (%rax),%edx
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rax
movsbl (%rax),%edx
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <munmap@plt>
cmp    $0xffffffff,%eax
jne    1302 <main+0x192>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xd94(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
mov    %rax,%r14
mov    0x2e6c(%rip),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e02(%rip),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2dd2(%rip),%rax
cmp    (%rax),%rbx
je     123a <main+0xca>
mov    %rbx,%rbp
add    $0xfff,%rbp
movb   $0xa,(%rbx)
movb   $0x14,0xfff(%rbx)
lea    0xe2f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl (%rbx),%edx
lea    0xe3b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movsbl 0xfff(%rbx),%edx
lea    0xe4a(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <munmap@plt>
cmp    $0xffffffff,%eax
je     125c <main+0xec>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d8f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7e(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xda6(%rip),%rsi
jmp    127c <main+0x10c>
mov    0x2d6d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d5c(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xe07(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [21 x i8] c"Err.(%d) mmap(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c" Allocated Memory: %d Kb\0A\00"
@.str.2 = [39 x i8] c"Allocated Memory starts: %p - Val: %d\0A\00"
@.str.3 = [39 x i8] c" Allocated Memory ends: %p - Val: %d\0A\00"
@.str.4 = [23 x i8] c"Err.(%d) munmap(): %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @_SC_PAGESIZE
%13 = call i64 @sysconf(i32 %12)
store i64 %13, i64* %7
%14 = load i32, i32* @PROT_READ
%15 = load i32, i32* @PROT_WRITE
%16 = or i32 %14, %15
store i32 %16, i32* %8
%17 = load i32, i32* @MAP_PRIVATE
%18 = load i32, i32* @MAP_ANON
%19 = or i32 %17, %18
store i32 %19, i32* %9
%20 = load i64, i64* %7
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = call i8* @mmap(i32* null, i64 %20, i32 %21, i32 %22, i32 -1, i32 0)
store i8* %23, i8** %6
%24 = load i8*, i8** @MAP_FAILED
%25 = icmp eq i8* %23, %24
br i1 %25, label %26, label %34
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %2
%35 = load i8*, i8** %6
store i8* %35, i8** %10
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 4095
store i8* %37, i8** %11
%38 = load i8*, i8** %10
store i8 10, i8* %38
%39 = load i8*, i8** %11
store i8 20, i8* %39
%40 = load i64, i64* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %40)
%42 = load i8*, i8** %10
%43 = load i8*, i8** %10
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %42, i32 %45)
%47 = load i8*, i8** %11
%48 = load i8*, i8** %11
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %47, i32 %50)
%52 = load i8*, i8** %6
%53 = load i64, i64* %7
%54 = call i32 @munmap(i8* %52, i64 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %64
56: ; preds = %34
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %58, i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %34
%65 = load i32, i32* @EXIT_SUCCESS
ret i32 %65
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
@stderr = global i32 0
@.str = [21 x i8] c"Err.(%d) mmap(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c" Allocated Memory: %d Kb\0A\00"
@.str.2 = [39 x i8] c"Allocated Memory starts: %p - Val: %d\0A\00"
@.str.3 = [39 x i8] c" Allocated Memory ends: %p - Val: %d\0A\00"
@.str.4 = [23 x i8] c"Err.(%d) munmap(): %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @_SC_PAGESIZE
%4 = tail call i64 @sysconf(i32 %3)
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %6, %5
%8 = load i32, i32* @MAP_PRIVATE
%9 = load i32, i32* @MAP_ANON
%10 = or i32 %9, %8
%11 = tail call i8* @mmap(i32* null, i64 %4, i32 %7, i32 %10, i32 -1, i32 0)
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = getelementptr inbounds i8, i8* %11, i64 4095
store i8 10, i8* %11
store i8 20, i8* %22
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%24 = load i8, i8* %11
%25 = sext i8 %24 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %11, i32 %25)
%27 = load i8, i8* %22
%28 = sext i8 %27 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %22, i32 %28)
%30 = tail call i32 @munmap(i8* %11, i64 %4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %39
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %34, i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %21
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}