#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;
typedef int mode_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mq_close(int);
int mq_open(char *, int, int, int /*<<< orphan*/ *);
int mq_unlink(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int flags = O_CREAT | O_RDWR;
  mode_t perms = S_IRUSR | S_IWUSR;
  mqd_t mqd = 0;
  mqd = mq_open("/mq", flags, perms, NULL);
  if (mqd == -1)
    do {
      perror("Message queue create failed");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Message queue created\n");
  if (mq_close(mqd) == -1)
    do {
      perror("Message queue close failed");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Message queue closed\n");
  if (mq_unlink("/mq") == -1)
    do {
      perror("Message queue unlink failed");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Message queue unlinked\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    0x2e5a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    0x2e3d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <mq_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e9 <main+0x89>
jmp    11cf <main+0x6f>
lea    0xe2e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <mq_close@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0xc5>
jmp    120b <main+0xab>
lea    0xe25(%rip),%rdi
call   1060 <perror@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
lea    0xdc8(%rip),%rdi
call   1080 <mq_unlink@plt>
cmp    $0xffffffff,%eax
jne    1265 <main+0x105>
jmp    124b <main+0xeb>
lea    0xe16(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e46(%rip),%rax
mov    0x2e57(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe74(%rip),%rdi
xor    %ecx,%ecx
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11df <main+0x7f>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <mq_close@plt>
cmp    $0xffffffff,%eax
je     11e8 <main+0x88>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3b(%rip),%rdi
call   1080 <mq_unlink@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0x91>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe1e(%rip),%rdi
jmp    11f8 <main+0x98>
lea    0xe31(%rip),%rdi
jmp    11f8 <main+0x98>
lea    0xe43(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [4 x i8] c"/mq\00"
@.str.1 = [28 x i8] c"Message queue create failed\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [23 x i8] c"Message queue created\0A\00"
@.str.3 = [27 x i8] c"Message queue close failed\00"
@.str.4 = [22 x i8] c"Message queue closed\0A\00"
@.str.5 = [28 x i8] c"Message queue unlink failed\00"
@.str.6 = [24 x i8] c"Message queue unlinked\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_RDWR
%11 = or i32 %9, %10
store i32 %11, i32* %6
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
store i32 %14, i32* %7
store i32 0, i32* %8
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = call i32 @mq_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16, i32* null)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %2
br label %21
21: ; preds = %20
%22 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; No predecessors!
br label %26
26: ; preds = %25, %2
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* %8
%29 = call i32 @mq_close(i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %26
br label %32
32: ; preds = %31
%33 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; No predecessors!
br label %37
37: ; preds = %36, %26
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @mq_unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %47
41: ; preds = %37
br label %42
42: ; preds = %41
%43 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; No predecessors!
br label %47
47: ; preds = %46, %37
%48 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [4 x i8] c"/mq\00"
@.str.1 = [28 x i8] c"Message queue create failed\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"Message queue close failed\00"
@.str.5 = [28 x i8] c"Message queue unlink failed\00"
@str = [22 x i8] c"Message queue created\00"
@str.7 = [21 x i8] c"Message queue closed\00"
@str.8 = [23 x i8] c"Message queue unlinked\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_RDWR
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %7, %6
%9 = tail call i32 @mq_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8, i32* null)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @mq_close(i32 %9)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%25 = tail call i32 @mq_unlink(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}