#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 mq_maxmsg;
  int mq_msgsize;
};
typedef int /*<<< orphan*/ mqd_t;

/* Variables and functions */
int O_CREAT;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mq_close(int /*<<< orphan*/);
int /*<<< orphan*/ mq_open(char *, int, int, struct mq_attr *);
int mq_receive(int /*<<< orphan*/, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  struct mq_attr attr = {
      .mq_maxmsg = 10,
      .mq_msgsize = 4096,
  };
  mqd_t msg_fd;
  char buffer[4096];
  msg_fd = mq_open("/my_mq", O_RDWR | O_CREAT | O_EXCL, 0666, &attr);
  while (1) {
    if ((mq_receive(msg_fd, buffer, attr.mq_msgsize, NULL)) == -1)
      exit(-1);
    printf("Message Received %s", buffer);
  }
  mq_close(msg_fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
mov    0x2e53(%rip),%rax
or     (%rax),%esi
lea    0xe82(%rip),%rdi
mov    $0x1b6,%edx
lea    -0x18(%rbp),%rcx
call   1040 <mq_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <mq_receive@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x80>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    -0x1020(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
jmp    1197 <main+0x57>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1010,%rsp
mov    0x2e8e(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movabs $0x10000000000a,%rax
mov    %rax,0x8(%rsp)
mov    0x2e5d(%rip),%rax
or     (%rax),%esi
lea    0xe84(%rip),%rdi
lea    0x8(%rsp),%rcx
mov    $0x1b6,%edx
call   1040 <mq_open@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
xor    %ecx,%ecx
call   1050 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x90>
lea    0xe5c(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1050 <mq_receive@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x70>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32 }
@__const.main.attr = %struct.mq_attr { i32 10, i32 4096 }
@.str = [7 x i8] c"/my_mq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [20 x i8] c"Message Received %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.mq_attr
%7 = alloca i32
%8 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast %struct.mq_attr* %6 to i8*
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_EXCL
%14 = or i32 %12, %13
%15 = call i32 @mq_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14, i32 438, %struct.mq_attr* %6)
store i32 %15, i32* %7
br label %16
16: ; preds = %2, %25
%17 = load i32, i32* %7
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%19 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 @mq_receive(i32 %17, i8* %18, i32 %20, i32* null)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %16
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %16
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32 }
@.str = [7 x i8] c"/my_mq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.1 = [20 x i8] c"Message Received %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.mq_attr*
%5 = alloca [4096 x i8]
%6 = bitcast i64* %3 to i8*
store i64 17592186044426, i64* %3
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_EXCL
%12 = or i32 %10, %11
%13 = call i32 @mq_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12, i32 438, %struct.mq_attr* %4)
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i64 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 @mq_receive(i32 %13, i8* %7, i32 %15, i32* null)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %20, %2
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2, %20
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%22 = load i32, i32* %14
%23 = call i32 @mq_receive(i32 %13, i8* %7, i32 %22, i32* null)
%24 = icmp eq i32 %23, -1
br i1 %24, label %18, label %20
}