#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 */
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int shm_open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shm_unlink(char *);
int main() {
  shm_unlink("/test");
  int fd = shm_open("/test", O_RDWR | O_CREAT, (mode_t)0600);
  int *map = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  map[0] = 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1050 <shm_unlink@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2ea4(%rip),%rax
or     (%rax),%esi
lea    0xea3(%rip),%rdi
mov    $0x180,%edx
call   1040 <shm_open@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
mov    0x2e46(%rip),%rax
or     (%rax),%edx
mov    0x2e5d(%rip),%rax
mov    (%rax),%ecx
mov    -0x4(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x4,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rbx
mov    %rbx,%rdi
call   1050 <shm_unlink@plt>
mov    0x2e89(%rip),%rax
mov    0x2eaa(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x180,%edx
call   1040 <shm_open@plt>
mov    0x2e8a(%rip),%rcx
mov    0x2e53(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e68(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0x4,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
movl   $0x0,(%rax)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"/test\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32 @shm_unlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = call i32 @shm_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6, i32 384)
store i32 %7, i32* %1
%8 = load i32, i32* @PROT_READ
%9 = load i32, i32* @PROT_WRITE
%10 = or i32 %8, %9
%11 = load i32, i32* @MAP_SHARED
%12 = load i32, i32* %1
%13 = call i32* @mmap(i32* null, i32 4, i32 %10, i32 %11, i32 %12, i32 0)
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 0, i32* %15
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"/test\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i32 @main() {
%1 = tail call i32 @shm_unlink(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @shm_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %4, i32 384)
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @PROT_WRITE
%8 = or i32 %7, %6
%9 = load i32, i32* @MAP_SHARED
%10 = tail call i32* @mmap(i32* null, i32 4, i32 %8, i32 %9, i32 %5, i32 0)
store i32 0, i32* %10
ret i32 0
}