#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;
void *MAP_FAILED;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ syserr(char *);
void *createSharedOfSize(int size) {
  void *mapped_mem;
  int fd_memory = -1;
  int flags, prot;
  prot = PROT_READ | PROT_WRITE;
  flags = MAP_SHARED | MAP_ANONYMOUS;
  mapped_mem = mmap(NULL, size, prot, flags, fd_memory, 0);
  if (mapped_mem == MAP_FAILED)
    syserr("mmap");
  return mapped_mem;
}


x86 assembly (clang, -O0):
<createSharedOfSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    0x2e86(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    0x2e81(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
jne    1199 <createSharedOfSize+0x79>
lea    0xe6c(%rip),%rdi
call   1040 <syserr@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createSharedOfSize>:
push   %rbx
mov    %edi,%esi
mov    0x2ece(%rip),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2eac(%rip),%rax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2e5f(%rip),%rax
cmp    (%rax),%rbx
jne    1172 <createSharedOfSize+0x52>
lea    0xe93(%rip),%rdi
call   1040 <syserr@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i8* @createSharedOfSize(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %4
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
store i32 %9, i32* %6
%10 = load i32, i32* @MAP_SHARED
%11 = load i32, i32* @MAP_ANONYMOUS
%12 = or i32 %10, %11
store i32 %12, i32* %5
%13 = load i32, i32* %2
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = call i8* @mmap(i32* null, i32 %13, i32 %14, i32 %15, i32 %16, i32 0)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** @MAP_FAILED
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @syserr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %1
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i8* @createSharedOfSize(i32 %0) {
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %3, %2
%5 = load i32, i32* @MAP_SHARED
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %6, %5
%8 = tail call i8* @mmap(i32* null, i32 %0, i32 %4, i32 %7, i32 -1, i32 0)
%9 = load i8*, i8** @MAP_FAILED
%10 = icmp eq i8* %8, %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = tail call i32 @syserr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
ret i8* %8
}