#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 IPC_CREAT;
int IPC_EXCL;
int msgget(int /*<<< orphan*/, int);
int open_queue(key_t keyval, int flag) {
  int qid;
  if (flag == 0) {
    if ((qid = msgget(keyval, IPC_CREAT | IPC_EXCL | 0660)) == -1) {
      return (-1);
    }
  } else {
    if ((qid = msgget(keyval, 0660)) == -1) {
      return (-1);
    }
  }
  return (qid);
}


x86 assembly (clang, -O0):
<open_queue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1165 <open_queue+0x55>
mov    -0x8(%rbp),%edi
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
mov    0x2eb5(%rip),%rax
or     (%rax),%esi
or     $0x1b0,%esi
call   1030 <msgget@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    1160 <open_queue+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <open_queue+0x85>
jmp    118f <open_queue+0x7f>
mov    -0x8(%rbp),%edi
mov    $0x1b0,%esi
call   1030 <msgget@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    118a <open_queue+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <open_queue+0x85>
jmp    118f <open_queue+0x7f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_queue>:
push   %rax
test   %esi,%esi
je     111c <open_queue+0xc>
mov    $0x1b0,%esi
jmp    1134 <open_queue+0x24>
mov    0x2eb5(%rip),%rax
mov    (%rax),%esi
mov    0x2ec4(%rip),%rax
or     (%rax),%esi
or     $0x1b0,%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     1140 <open_queue+0x30>
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
define i32 @open_queue(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i32, i32* %4
%11 = load i32, i32* @IPC_CREAT
%12 = load i32, i32* @IPC_EXCL
%13 = or i32 %11, %12
%14 = or i32 %13, 432
%15 = call i32 @msgget(i32 %10, i32 %14)
store i32 %15, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %9
store i32 -1, i32* %3
br label %27
18: ; preds = %9
br label %25
19: ; preds = %2
%20 = load i32, i32* %4
%21 = call i32 @msgget(i32 %20, i32 432)
store i32 %21, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -1, i32* %3
br label %27
24: ; preds = %19
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %23, %17
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
define i32 @open_queue(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = load i32, i32* @IPC_CREAT
%6 = load i32, i32* @IPC_EXCL
%7 = or i32 %5, %6
%8 = or i32 %7, 432
%9 = tail call i32 @msgget(i32 %0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %14
11: ; preds = %2
%12 = tail call i32 @msgget(i32 %0, i32 432)
%13 = icmp eq i32 %12, -1
br i1 %13, label %16, label %14
14: ; preds = %11, %4
%15 = phi i32 [ %9, %4 ], [ %12, %11 ]
br label %16
16: ; preds = %11, %4, %14
%17 = phi i32 [ %15, %14 ], [ -1, %4 ], [ -1, %11 ]
ret i32 %17
}