#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 semget(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int get_sem(const char *path) {
  key_t key;
  int semid = -1;
  key = get_key(path);
  if (key == -1)
    return -1;
  semid = semget(key, 0, 0);
  if (semid == -1)
    fprintf(stderr, "get_sem(%s)::semget: %s\n", path, strerror(errno));
  return semid;
}


x86 assembly (clang, -O0):
<get_sem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <get_key@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1175 <get_sem+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <get_sem+0x8c>
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <semget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c6 <get_sem+0x86>
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   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sem>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <get_key@plt>
mov    %eax,%edi
mov    $0xffffffff,%eax
cmp    $0xffffffff,%edi
je     1195 <get_sem+0x55>
xor    %esi,%esi
xor    %edx,%edx
call   1030 <semget@plt>
cmp    $0xffffffff,%eax
jne    1195 <get_sem+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   1040 <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_sem(%s)::semget: %s\0A\00"
@errno = global i32 0
define i32 @get_sem(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 %24
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i32 @semget(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 %22
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)
br label %22
22: ; preds = %16, %11
%23 = load i32, i32* %5
store i32 %23, i32* %2
br label %24
24: ; preds = %22, %10
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"get_sem(%s)::semget: %s\0A\00"
@errno = global i32 0
define i32 @get_sem(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 @semget(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, %7, %1
%13 = phi i32 [ -1, %1 ], [ -1, %7 ], [ %5, %4 ]
ret i32 %13
}