#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;
int MAP_SHARED;
int /*<<< orphan*/ PROT_WRITE;
int getpagesize();
int *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int, int /*<<< orphan*/,
          int /*<<< orphan*/);
int /*<<< orphan*/ munmap(int *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int *p = mmap(0, getpagesize(), PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0);
  *p = 20;
  *(p + 1) = 30;
  *(p + 2) = 40;
  printf("%d\n", p[2]);
  munmap(p, getpagesize());
  printf("--%d\n", getpagesize());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    %eax,%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    0x2e78(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7f(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    %r9d,%edi
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x14,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1e,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x28,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1050 <munmap@plt>
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    %eax,%esi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <getpagesize@plt>
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e88(%rip),%rsi
mov    0x2e91(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
xor    %edi,%edi
mov    %eax,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
movabs $0x1e00000014,%rax
mov    %rax,(%rbx)
movl   $0x28,0x8(%rbx)
lea    0xe72(%rip),%rdi
mov    $0x28,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getpagesize@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <munmap@plt>
xor    %eax,%eax
call   1060 <getpagesize@plt>
lea    0xe47(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_SHARED = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [6 x i8] c"--%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32 (...) @getpagesize()
%4 = load i32, i32* @PROT_WRITE
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = load i32, i32* @MAP_SHARED
%7 = or i32 %5, %6
%8 = call i32* @mmap(i32 0, i32 %3, i32 %4, i32 %7, i32 0, i32 0)
store i32* %8, i32** %2
%9 = load i32*, i32** %2
store i32 20, i32* %9
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 1
store i32 30, i32* %11
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 2
store i32 40, i32* %13
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 2
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 (...) @getpagesize()
%20 = call i32 @munmap(i32* %18, i32 %19)
%21 = call i32 (...) @getpagesize()
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
ret i32 0
}

LLVM IR (-O2):
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_SHARED = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [6 x i8] c"--%d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpagesize()
%2 = load i32, i32* @PROT_WRITE
%3 = load i32, i32* @MAP_ANONYMOUS
%4 = load i32, i32* @MAP_SHARED
%5 = or i32 %4, %3
%6 = tail call i32* @mmap(i32 0, i32 %1, i32 %2, i32 %5, i32 0, i32 0)
store i32 20, i32* %6
%7 = getelementptr inbounds i32, i32* %6, i64 1
store i32 30, i32* %7
%8 = getelementptr inbounds i32, i32* %6, i64 2
store i32 40, i32* %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 40)
%10 = tail call i32 (...) @getpagesize()
%11 = tail call i32 @munmap(i32* %6, i32 %10)
%12 = tail call i32 (...) @getpagesize()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret i32 0
}