#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 */
struct mq_attr {
  int dummy;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int mq_open(char *, int, int, struct mq_attr *);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ perror(char *);
int open_make_mq(char *filename, struct mq_attr *attr) {
  mq_unlink(filename);
  int mq = mq_open(filename, O_RDWR | O_CREAT, 0660, attr);
  if (mq == -1) {
    perror("error creating mq");
    exit(1);
  }
  return mq;
}


x86 assembly (clang, -O0):
<open_make_mq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <mq_unlink@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e8b(%rip),%rax
or     (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1b0,%edx
call   1030 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a0 <open_make_mq+0x60>
lea    0xe6f(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_make_mq>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <mq_unlink@plt>
mov    0x2e8a(%rip),%rax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b0,%edx
mov    %r14,%rcx
call   1030 <mq_open@plt>
cmp    $0xffffffff,%eax
je     117e <open_make_mq+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [18 x i8] c"error creating mq\00"
define i32 @open_make_mq(i8* %0, %struct.mq_attr* %1) {
%3 = alloca i8*
%4 = alloca %struct.mq_attr*
%5 = alloca i32
store i8* %0, i8** %3
store %struct.mq_attr* %1, %struct.mq_attr** %4
%6 = load i8*, i8** %3
%7 = call i32 @mq_unlink(i8* %6)
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load %struct.mq_attr*, %struct.mq_attr** %4
%13 = call i32 @mq_open(i8* %8, i32 %11, i32 432, %struct.mq_attr* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* %5
ret i32 %20
}

LLVM IR (-O2):
%struct.mq_attr = type { i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [18 x i8] c"error creating mq\00"
define i32 @open_make_mq(i8* %0, %struct.mq_attr* %1) {
%3 = tail call i32 @mq_unlink(i8* %0)
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 @mq_open(i8* %0, i32 %6, i32 432, %struct.mq_attr* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
ret i32 %7
}