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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int msgget(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int create_msq(key_t key, int perms) {
  int msqid;
  if (perms) {
    perms |= IPC_CREAT | IPC_EXCL;
  }
  if ((msqid = msgget(key, perms)) == -1) {
    perror("msgget(key, perms)");
    exit(EXIT_FAILURE);
  }
  return msqid;
}


x86 assembly (clang, -O0):
<create_msq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1160 <create_msq+0x30>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    0x2e98(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <msgget@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1191 <create_msq+0x61>
lea    0xe82(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_msq>:
push   %rax
mov    0x2e98(%rip),%rax
mov    0x2eb1(%rip),%rcx
mov    (%rax),%eax
or     %esi,%eax
or     (%rcx),%eax
test   %esi,%esi
cmovne %eax,%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     1156 <create_msq+0x26>
pop    %rcx
ret
lea    0xea3(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str = [19 x i8] c"msgget(key, perms)\00"
@EXIT_FAILURE = global i32 0
define i32 @create_msq(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @IPC_CREAT
%10 = load i32, i32* @IPC_EXCL
%11 = or i32 %9, %10
%12 = load i32, i32* %4
%13 = or i32 %12, %11
store i32 %13, i32* %4
br label %14
14: ; preds = %8, %2
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @msgget(i32 %15, i32 %16)
store i32 %17, i32* %5
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@.str = [19 x i8] c"msgget(key, perms)\00"
@EXIT_FAILURE = global i32 0
define i32 @create_msq(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = load i32, i32* @IPC_CREAT
%5 = load i32, i32* @IPC_EXCL
%6 = or i32 %4, %1
%7 = or i32 %6, %5
%8 = select i1 %3, i32 0, i32 %7
%9 = tail call i32 @msgget(i32 %0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
ret i32 %9
}