#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 NAME_MAX;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ plrSD_getShmName(char *);
int shm_open(char *, int, int /*<<< orphan*/);
int plrSD_openShmFile(int oflag, mode_t mode) {
  char shmName[NAME_MAX];
  plrSD_getShmName(shmName);
  int shmFd = shm_open(shmName, oflag, mode);
  if (shmFd < 0) {
    perror("shm_open");
    return -1;
  }
  return shmFd;
}


x86 assembly (clang, -O0):
<plrSD_openShmFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
call   1030 <plrSD_getShmName@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <shm_open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11aa <plrSD_openShmFile+0x7a>
lea    0xe6e(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11b7 <plrSD_openShmFile+0x87>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plrSD_openShmFile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1030 <plrSD_getShmName@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1050 <shm_open@plt>
test   %eax,%eax
js     117f <plrSD_openShmFile+0x4f>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    1174 <plrSD_openShmFile+0x44>

LLVM IR (-O0):
@NAME_MAX = global i32 0
@.str = [9 x i8] c"shm_open\00"
define i32 @plrSD_openShmFile(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = load i32, i32* @NAME_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = call i32 @plrSD_getShmName(i8* %13)
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @shm_open(i8* %13, i32 %15, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %9
br label %24
22: ; preds = %2
%23 = load i32, i32* %8
store i32 %23, i32* %3
store i32 1, i32* %9
br label %24
24: ; preds = %22, %20
%25 = load i8*, i8** %6
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@NAME_MAX = global i32 0
@.str = [9 x i8] c"shm_open\00"
define i32 @plrSD_openShmFile(i32 %0, i32 %1) {
%3 = load i32, i32* @NAME_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @plrSD_getShmName(i8* %5)
%7 = call i32 @shm_open(i8* %5, i32 %0, i32 %1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %2, %9
%12 = phi i32 [ -1, %9 ], [ %7, %2 ]
ret i32 %12
}