#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 mqd_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int mq_open(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int open_mq(mqd_t *mqd, char *pathname) {
  mqd_t temp;
  if ((temp = mq_open(pathname, O_RDWR | O_CREAT,
                      S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, NULL)) == -1) {
    perror("mq_open");
    return -1;
  }
  *mqd = temp;
  return 1;
}


x86 assembly (clang, -O0):
<open_mq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
mov    0x2eb4(%rip),%rax
or     (%rax),%esi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
mov    0x2e62(%rip),%rax
or     (%rax),%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
mov    0x2e58(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <mq_open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1197 <open_mq+0x77>
lea    0xe7a(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <open_mq+0x87>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_mq>:
push   %rbx
mov    0x2eb8(%rip),%rcx
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e9e(%rip),%rcx
mov    0x2e77(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e7c(%rip),%rcx
or     (%rcx),%edx
mov    %rdi,%rbx
mov    0x2e68(%rip),%rcx
or     (%rcx),%edx
mov    %rsi,%rdi
mov    %eax,%esi
xor    %ecx,%ecx
call   1030 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1174 <open_mq+0x54>
mov    %eax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [8 x i8] c"mq_open\00"
define i32 @open_mq(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IWUSR
%12 = load i32, i32* @S_IRUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = call i32 @mq_open(i8* %7, i32 %10, i32 %17, i32* null)
store i32 %18, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
22: ; preds = %2
%23 = load i32, i32* %6
%24 = load i32*, i32** %4
store i32 %23, i32* %24
store i32 1, i32* %3
br label %25
25: ; preds = %22, %20
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [8 x i8] c"mq_open\00"
define i32 @open_mq(i32* nocapture writeonly %0, i8* %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IWUSR
%7 = load i32, i32* @S_IRUSR
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IRGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
%13 = tail call i32 @mq_open(i8* %1, i32 %5, i32 %12, i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %18
17: ; preds = %2
store i32 %13, i32* %0
br label %18
18: ; preds = %17, %15
%19 = phi i32 [ -1, %15 ], [ 1, %17 ]
ret i32 %19
}