#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_NONBLOCK;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mq_open(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setup_notify(int *);
int main(int argc, char *argv[]) {
  int flags = O_CREAT | O_RDWR | O_NONBLOCK;
  mode_t perms = S_IRUSR | S_IWUSR;
  mqd_t mqd;
  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");
  setup_notify(&mqd);
  pause();
  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    0x2e49(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    0x2e2c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <mq_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11eb <main+0x8b>
jmp    11d1 <main+0x71>
lea    0xe2c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <setup_notify@plt>
mov    $0x0,%al
call   1050 <pause@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e5e(%rip),%rax
or     (%rax),%esi
mov    0x2e35(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe6b(%rip),%rdi
xor    %ecx,%ecx
call   1040 <mq_open@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     11c6 <main+0x66>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1060 <setup_notify@plt>
xor    %eax,%eax
call   1050 <pause@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = 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"
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
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %11, %12
store i32 %13, i32* %6
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %14, %15
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @mq_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32* null)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %2
br label %23
23: ; preds = %22
%24 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; No predecessors!
br label %28
28: ; preds = %27, %2
%29 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @setup_notify(i32* %8)
%31 = call i32 (...) @pause()
ret i32 0
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = 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 = [22 x i8] c"Message queue created\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_RDWR
%6 = or i32 %5, %4
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = bitcast i32* %3 to i8*
%13 = tail call i32 @mq_open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32* null)
store i32 %13, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%21 = call i32 @setup_notify(i32* %3)
%22 = call i32 (...) @pause()
ret i32 0
}