#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 key_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int get_key(char const *);
int shmget(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int get_shm(const char *path) {
  key_t key;
  int shmid = -1;
  key = get_key(path);
  if (key == -1)
    return -1;
  shmid = shmget(key, 0, 0);
  if (shmid == -1) {
    fprintf(stderr, "get_shm(%s)::shmget: %s\n", path, strerror(errno));
    return shmid;
  }
  return shmid;
}


x86 assembly (clang, -O0):
<get_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <get_key@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1175 <get_shm+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <get_shm+0x97>
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <shmget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11d1 <get_shm+0x91>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe3f(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <get_shm+0x97>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_shm>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <get_key@plt>
mov    %eax,%edi
mov    $0xffffffff,%eax
cmp    $0xffffffff,%edi
je     1195 <get_shm+0x55>
xor    %esi,%esi
xor    %edx,%edx
call   1050 <shmget@plt>
cmp    $0xffffffff,%eax
jne    1195 <get_shm+0x55>
mov    0x2e74(%rip),%rax
mov    (%rax),%ebp
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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