#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*/ getchar();
scalar_t__ mmap(void *, int, int, int, int, int /*<<< orphan*/);
int munmap(unsigned char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  unsigned char *ptr = NULL, *temp;
  getchar();
  ptr = (char *)mmap((void *)0, 1024 * 128, PROT_READ | PROT_WRITE,
                     MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  if (ptr == NULL) {
    perror("Maping Failed");
    exit(1);
  }
  getchar();
  temp = ptr;
  for (i = 0; i < 60; i++, ptr++)
    *ptr = (char)(i + 65);
  ptr = temp;
  for (i = 0; i < 60; i++, ptr++)
    printf("%c", *ptr);
  i = munmap(temp, 1024 * 128);
  getchar();
  if (i != 0)
    printf(" failed to unmap\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    0x2e42(%rip),%rax
or     (%rax),%edx
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
mov    0x2e28(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x20000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11de <main+0x7e>
lea    0xe31(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3c,-0x8(%rbp)
jge    1226 <main+0xc6>
mov    -0x8(%rbp),%eax
add    $0x41,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11f4 <main+0x94>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3c,-0x8(%rbp)
jge    126e <main+0x10e>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1235 <main+0xd5>
mov    -0x18(%rbp),%rdi
mov    $0x20000,%esi
call   1060 <munmap@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
cmpl   $0x0,-0x8(%rbp)
je     129e <main+0x13e>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e76(%rip),%rax
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e4c(%rip),%rax
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x20000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     1253 <main+0xe3>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
movaps 0xe30(%rip),%xmm0
movups %xmm0,(%r14)
movaps 0xe35(%rip),%xmm0
movups %xmm0,0x10(%r14)
movaps 0xe39(%rip),%xmm0
movups %xmm0,0x20(%r14)
movabs $0x7877767574737271,%rax
76 77 78
mov    %rax,0x30(%r14)
movl   $0x7c7b7a79,0x38(%r14)
7c
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    $0x3c,%ebx
jne    1210 <main+0xa0>
mov    %r14,%rdi
mov    $0x20000,%esi
call   1070 <munmap@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
test   %ebx,%ebx
je     1249 <main+0xd9>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdd6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@.str = [14 x i8] c"Maping Failed\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [18 x i8] c" failed to unmap\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %3
%5 = call i32 (...) @getchar()
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %6, %7
%9 = load i32, i32* @MAP_ANONYMOUS
%10 = load i32, i32* @MAP_PRIVATE
%11 = or i32 %9, %10
%12 = call i64 @mmap(i8* null, i32 131072, i32 %8, i32 %11, i32 -1, i32 0)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = call i32 (...) @getchar()
%21 = load i8*, i8** %3
store i8* %21, i8** %4
store i32 0, i32* %2
br label %22
22: ; preds = %30, %19
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 60
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 65
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %3
store i8 %28, i8* %29
br label %30
30: ; preds = %25
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %22
35: ; preds = %22
%36 = load i8*, i8** %4
store i8* %36, i8** %3
store i32 0, i32* %2
br label %37
37: ; preds = %45, %35
%38 = load i32, i32* %2
%39 = icmp slt i32 %38, 60
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %40
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %3
br label %37
50: ; preds = %37
%51 = load i8*, i8** %4
%52 = call i32 @munmap(i8* %51, i32 131072)
store i32 %52, i32* %2
%53 = call i32 (...) @getchar()
%54 = load i32, i32* %2
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56, %50
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@.str = [14 x i8] c"Maping Failed\00"
@str = [17 x i8] c" failed to unmap\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = load i32, i32* @MAP_PRIVATE
%7 = or i32 %6, %5
%8 = tail call i64 @mmap(i8* null, i32 131072, i32 %4, i32 %7, i32 -1, i32 0)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = tail call i32 (...) @getchar()
%16 = getelementptr i8, i8* %9, i64 48
%17 = inttoptr i64 %8 to <16 x i8>*
store <16 x i8> <i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79, i8 80>, <16 x i8>* %17
%18 = getelementptr i8, i8* %9, i64 16
%19 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> <i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95, i8 96>, <16 x i8>* %19
%20 = getelementptr i8, i8* %9, i64 32
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> <i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112>, <16 x i8>* %21
store i8 113, i8* %16
%22 = getelementptr i8, i8* %9, i64 49
store i8 114, i8* %22
%23 = getelementptr i8, i8* %9, i64 50
store i8 115, i8* %23
%24 = getelementptr i8, i8* %9, i64 51
store i8 116, i8* %24
%25 = getelementptr i8, i8* %9, i64 52
store i8 117, i8* %25
%26 = getelementptr i8, i8* %9, i64 53
store i8 118, i8* %26
%27 = getelementptr i8, i8* %9, i64 54
store i8 119, i8* %27
%28 = getelementptr i8, i8* %9, i64 55
store i8 120, i8* %28
%29 = getelementptr i8, i8* %9, i64 56
store i8 121, i8* %29
%30 = getelementptr i8, i8* %9, i64 57
store i8 122, i8* %30
%31 = getelementptr i8, i8* %9, i64 58
store i8 123, i8* %31
%32 = getelementptr i8, i8* %9, i64 59
store i8 124, i8* %32
br label %33
33: ; preds = %14, %33
%34 = phi i32 [ %39, %33 ], [ 0, %14 ]
%35 = phi i8* [ %40, %33 ], [ %9, %14 ]
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = tail call i32 @putchar(i32 %37)
%39 = add nuw nsw i32 %34, 1
%40 = getelementptr inbounds i8, i8* %35, i64 1
%41 = icmp eq i32 %39, 60
br i1 %41, label %42, label %33
42: ; preds = %33
%43 = tail call i32 @munmap(i8* %9, i32 131072)
%44 = tail call i32 (...) @getchar()
%45 = icmp eq i32 %43, 0
br i1 %45, label %48, label %46
46: ; preds = %42
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
ret i32 0
}