#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_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int munmap(void *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  void *p;
  int i;
  p = mmap(NULL, 0x100000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
           -1, 0);
  if (p < 0) {
    perror("map failed ");
    exit(-1);
  }
  memset((unsigned char *)p, 0xac, 1024);
  for (i = 0; i < 16; i++) {
    printf("%x ", *(unsigned char *)((unsigned char *)p + i));
  }
  printf("\n");
  int ret = munmap(p, 0x100000);
  if (ret < 0)
    perror("umap fail ");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    0x2e51(%rip),%rax
or     (%rax),%edx
mov    0x2e58(%rip),%rax
mov    (%rax),%ecx
mov    0x2e37(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x100000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jae    11cf <main+0x6f>
lea    0xe40(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    $0xac,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    121b <main+0xbb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e9 <main+0x89>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x100000,%esi
call   1060 <munmap@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1250 <main+0xf0>
lea    0xdc7(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e63(%rip),%rax
mov    0x2e44(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x100000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xac,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movzbl (%rbx),%esi
lea    0xe44(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x1(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x2(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x3(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x6(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x7(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x9(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xa(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xb(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xd(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xe(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x100000,%esi
call   1070 <munmap@plt>
test   %eax,%eax
js     12bd <main+0x15d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd40(%rip),%rdi
call   1080 <perror@plt>
jmp    12b3 <main+0x153>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@.str = [12 x i8] c"map failed \00"
@.str.1 = [4 x i8] c"%x \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [11 x i8] c"umap fail \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = load i32, i32* @MAP_PRIVATE
%10 = or i32 %8, %9
%11 = call i8* @mmap(i32* null, i32 1048576, i32 %7, i32 %10, i32 -1, i32 0)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = icmp ult i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 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 @memset(i8* %18, i32 172, i32 1024)
store i32 0, i32* %3
br label %20
20: ; preds = %31, %17
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 16
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %20
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = load i8*, i8** %2
%37 = call i32 @munmap(i8* %36, i32 1048576)
store i32 %37, i32* %4
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@.str.1 = [4 x i8] c"%x \00"
@.str.3 = [11 x i8] c"umap fail \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_ANONYMOUS
%5 = load i32, i32* @MAP_PRIVATE
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i32* null, i32 1048576, i32 %3, i32 %6, i32 -1, i32 0)
%8 = tail call i32 @memset(i8* %7, i32 172, i32 1024)
%9 = load i8, i8* %7
%10 = zext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %7, i64 2
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %7, i64 3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds i8, i8* %7, i64 4
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds i8, i8* %7, i64 5
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds i8, i8* %7, i64 6
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds i8, i8* %7, i64 7
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i8, i8* %7, i64 8
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds i8, i8* %7, i64 9
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds i8, i8* %7, i64 10
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds i8, i8* %7, i64 11
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds i8, i8* %7, i64 12
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds i8, i8* %7, i64 13
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds i8, i8* %7, i64 14
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds i8, i8* %7, i64 15
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %70)
%72 = tail call i32 @putchar(i32 10)
%73 = tail call i32 @munmap(i8* %7, i32 1048576)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %0
%76 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %77
77: ; preds = %75, %0
ret i32 0
}