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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ mq_close(scalar_t__);
scalar_t__ mq_open(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ puts(char *);
int main() {
  mqd_t mqd;
  mqd = mq_open("/ipc-mq", O_RDWR | O_CREAT, 0700, NULL);
  if ((int)mqd == -1) {
    puts("mq_open failed");
    return 1;
  }
  mq_close(mqd);
  mq_unlink("/ipc-mq");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
lea    0xe98(%rip),%rdi
mov    $0x1c0,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <mq_open@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0xffffffff,%eax
jne    119f <main+0x5f>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11bb <main+0x7b>
mov    -0x10(%rbp),%rdi
call   1040 <mq_close@plt>
lea    0xe51(%rip),%rdi
call   1060 <mq_unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e98(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea6(%rip),%rdi
xor    %ebx,%ebx
mov    $0x1c0,%edx
xor    %ecx,%ecx
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1183 <main+0x43>
mov    %rax,%rdi
call   1040 <mq_close@plt>
lea    0xe84(%rip),%rdi
call   1060 <mq_unlink@plt>
jmp    1194 <main+0x54>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/ipc-mq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [15 x i8] c"mq_open failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = call i64 @mq_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5, i32 448, i32* null)
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = trunc i64 %7 to i32
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %16
12: ; preds = %0
%13 = load i64, i64* %2
%14 = call i32 @mq_close(i64 %13)
%15 = call i32 @mq_unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %16
16: ; preds = %12, %10
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [8 x i8] c"/ipc-mq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [15 x i8] c"mq_open failed\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = tail call i64 @mq_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3, i32 448, i32* null)
%5 = trunc i64 %4 to i32
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %12
9: ; preds = %0
%10 = tail call i32 @mq_close(i64 %4)
%11 = tail call i32 @mq_unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %13
}