#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 /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ftruncate(int, size_t);
void *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int shm_open(char *, int, int);
int main(int argc, char *argv[]) {
  int shm_fd;
  void *shm_area;
  size_t size = 8192;
  shm_fd = shm_open("/my_shm", O_CREAT | O_RDWR | O_EXCL, 0666);
  ftruncate(shm_fd, size);
  shm_area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
  munmap(shm_area, size);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x2000,-0x28(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e52(%rip),%rax
or     (%rax),%esi
mov    0x2e39(%rip),%rax
or     (%rax),%esi
lea    0xe70(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <shm_open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1040 <ftruncate@plt>
mov    -0x28(%rbp),%rsi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
mov    0x2dfb(%rip),%rax
or     (%rax),%edx
mov    0x2e1a(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <munmap@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e56(%rip),%rax
or     (%rax),%esi
lea    0xe8d(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <shm_open@plt>
mov    %eax,%ebx
mov    $0x2000,%esi
mov    %eax,%edi
call   1040 <ftruncate@plt>
mov    0x2e5e(%rip),%rax
mov    0x2e1f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    $0x2000,%esi
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    $0x2000,%esi
mov    %rax,%rdi
call   1050 <munmap@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/my_shm\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 8192, i64* %8
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_RDWR
%11 = or i32 %9, %10
%12 = load i32, i32* @O_EXCL
%13 = or i32 %11, %12
%14 = call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %13, i32 438)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = load i64, i64* %8
%17 = call i32 @ftruncate(i32 %15, i64 %16)
%18 = load i64, i64* %8
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @PROT_WRITE
%21 = or i32 %19, %20
%22 = load i32, i32* @MAP_SHARED
%23 = load i32, i32* %6
%24 = call i8* @mmap(i32* null, i64 %18, i32 %21, i32 %22, i32 %23, i32 0)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i64, i64* %8
%27 = call i32 @munmap(i8* %25, i64 %26)
%28 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"/my_shm\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_RDWR
%5 = or i32 %4, %3
%6 = load i32, i32* @O_EXCL
%7 = or i32 %5, %6
%8 = tail call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7, i32 438)
%9 = tail call i32 @ftruncate(i32 %8, i64 8192)
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %11, %10
%13 = load i32, i32* @MAP_SHARED
%14 = tail call i8* @mmap(i32* null, i64 8192, i32 %12, i32 %13, i32 %8, i32 0)
%15 = tail call i32 @munmap(i8* %14, i64 8192)
%16 = tail call i32 @exit(i32 0)
unreachable
}