#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 */
char *MAP_FAILED;
int MAP_FILE;
int MAP_FIXED;
int MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int);
char *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int shm_open(char *, int /*<<< orphan*/, int);
int main() {
  int shmid;
  char *shm, *s;
  if ((shmid = shm_open("mymemory", O_RDWR, 0666)) < 0) {
    perror("shm_open");
    exit(1);
  }
  if ((shm = mmap((void *)2147483648, 10737418240, PROT_READ | PROT_WRITE,
                  MAP_FILE | MAP_SHARED | MAP_FIXED, shmid, 0)) == MAP_FAILED) {
    perror("mmap");
    exit(1);
  }
  for (s = shm; *s != '\0'; s++) {
    putchar(*s);
  }
  putchar('\n');
  *shm = '*';
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <shm_open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    119b <main+0x4b>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    0x2e15(%rip),%rax
or     (%rax),%edx
mov    0x2e1c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2b(%rip),%rax
or     (%rax),%ecx
mov    0x2df2(%rip),%rax
or     (%rax),%ecx
mov    -0x8(%rbp),%r8d
mov    $0x80000000,%edi
mov    $0x80000000,%esi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
jne    1208 <main+0xb8>
lea    0xe19(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123d <main+0xed>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1210 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
movb   $0x2a,(%rax)
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <shm_open@plt>
test   %eax,%eax
jns    117b <main+0x2b>
lea    0xe90(%rip),%rdi
jmp    11d3 <main+0x83>
mov    0x2e76(%rip),%rcx
mov    0x2e37(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e3c(%rip),%rsi
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
mov    0x2e12(%rip),%rsi
or     (%rsi),%ecx
mov    $0x80000000,%edi
mov    $0x80000000,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r14
mov    0x2de9(%rip),%rax
cmp    (%rax),%r14
jne    11e2 <main+0x92>
lea    0xe3f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    (%r14),%al
test   %al,%al
je     1203 <main+0xb3>
mov    %r14,%rbx
add    $0x1,%rbx
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11f0 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
movb   $0x2a,(%r14)
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"mymemory\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FIXED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i32 @shm_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5, i32 438)
store i32 %6, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %12, %13
%15 = load i32, i32* @MAP_FILE
%16 = load i32, i32* @MAP_SHARED
%17 = or i32 %15, %16
%18 = load i32, i32* @MAP_FIXED
%19 = or i32 %17, %18
%20 = load i32, i32* %2
%21 = call i8* @mmap(i8* inttoptr (i64 2147483648 to i8*), i32 -2147483648, i32 %14, i32 %19, i32 %20, i32 0)
store i8* %21, i8** %3
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %27
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %11
%28 = load i8*, i8** %3
store i8* %28, i8** %4
br label %29
29: ; preds = %38, %27
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = call i32 @putchar(i8 signext %36)
br label %38
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %4
br label %29
41: ; preds = %29
%42 = call i32 @putchar(i8 signext 10)
%43 = load i8*, i8** %3
store i8 42, i8* %43
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c"mymemory\00"
@O_RDWR = global i32 0
@.str.1 = [9 x i8] c"shm_open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FILE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FIXED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @shm_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1, i32 438)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %9, %8
%11 = load i32, i32* @MAP_FILE
%12 = load i32, i32* @MAP_SHARED
%13 = or i32 %12, %11
%14 = load i32, i32* @MAP_FIXED
%15 = or i32 %13, %14
%16 = tail call i8* @mmap(i8* inttoptr (i64 2147483648 to i8*), i32 -2147483648, i32 %10, i32 %15, i32 %2, i32 0)
%17 = load i8*, i8** @MAP_FAILED
%18 = icmp eq i8* %16, %17
br i1 %18, label %22, label %19
19: ; preds = %7
%20 = load i8, i8* %16
%21 = icmp eq i8 %20, 0
br i1 %21, label %32, label %25
22: ; preds = %7
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19, %25
%26 = phi i8 [ %30, %25 ], [ %20, %19 ]
%27 = phi i8* [ %29, %25 ], [ %16, %19 ]
%28 = tail call i32 @putchar(i8 signext %26)
%29 = getelementptr inbounds i8, i8* %27, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %25
32: ; preds = %25, %19
%33 = tail call i32 @putchar(i8 signext 10)
store i8 42, i8* %16
%34 = tail call i32 @exit(i32 0)
unreachable
}