#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*/ O_RDWR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int shm_open(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int get_shm(const char *path) {
  int shmid = -1;
  shmid = shm_open(path, O_RDWR, 0);
  if (shmid == -1)
    fprintf(stderr, "get_shm(%s)::shm_open: %s\n", path, strerror(errno));
  return shmid;
}


x86 assembly (clang, -O0):
<get_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <shm_open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    119c <get_shm+0x6c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe69(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_shm>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <shm_open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    117b <get_shm+0x4b>
mov    0x2e83(%rip),%rax
mov    (%rax),%r14d
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe93(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"get_shm(%s)::shm_open: %s\0A\00"
@errno = global i32 0
define i32 @get_shm(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = call i32 @shm_open(i8* %4, i32 %5, i32 0)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %13)
br label %15
15: ; preds = %9, %1
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"get_shm(%s)::shm_open: %s\0A\00"
@errno = global i32 0
define i32 @get_shm(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @shm_open(i8* %0, i32 %2, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
br label %10
10: ; preds = %5, %1
ret i32 %3
}