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


x86 assembly (clang, -O0):
<get_msg_queue>:
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_msg_queue+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <get_msg_queue+0x8a>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1030 <msgget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c4 <get_msg_queue+0x84>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe41(%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_msg_queue>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <get_key@plt>
mov    %eax,%edi
mov    $0xffffffff,%eax
cmp    $0xffffffff,%edi
je     1193 <get_msg_queue+0x53>
xor    %esi,%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
jne    1193 <get_msg_queue+0x53>
mov    0x2e76(%rip),%rax
mov    (%rax),%ebp
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7f(%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 = [31 x i8] c"get_msg_queue(%s)::msgget: %s\0A\00"
@errno = global i32 0
define i32 @get_msg_queue(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 @msgget(i32 %12, 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 ([31 x i8], [31 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 = [31 x i8] c"get_msg_queue(%s)::msgget: %s\0A\00"
@errno = global i32 0
define i32 @get_msg_queue(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 @msgget(i32 %2, 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 ([31 x i8], [31 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
}