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


x86 assembly (clang, -O0):
<create_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 <create_msg_queue+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <create_msg_queue+0xa0>
mov    -0x14(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
or     $0x180,%esi
call   1030 <msgget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11da <create_msg_queue+0x9a>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2b(%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):
<create_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     11a9 <create_msg_queue+0x69>
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    0x2e89(%rip),%rax
or     (%rax),%esi
or     $0x180,%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
jne    11a9 <create_msg_queue+0x69>
mov    0x2e58(%rip),%rax
mov    (%rax),%ebp
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe69(%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):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"create_msg_queue(%s)::msgget: %s\0A\00"
@errno = global i32 0
define i32 @create_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 %28
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32, i32* @IPC_CREAT
%14 = load i32, i32* @IPC_EXCL
%15 = or i32 %13, %14
%16 = or i32 %15, 384
%17 = call i32 @msgget(i32 %12, i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
br label %26
26: ; preds = %20, %11
%27 = load i32, i32* %5
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %10
%29 = load i32, i32* %2
ret i32 %29
}

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