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

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mq_open(char *, int, int, struct mq_attr *);
int mq_receive(int /*<<< orphan*/, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mq_unlink(char *);
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  struct mq_attr attr;
  attr.mq_flags = 0;
  attr.mq_maxmsg = 10;
  attr.mq_msgsize = 8192;
  mqd_t mq = mq_open("/test.mq", O_RDONLY | O_CREAT, 0666, &attr);
  char buf[8192];
  int result = mq_receive(mq, buf, 8192, 0);
  int fd = open("message.txt", O_WRONLY | O_CREAT, 0666);
  write(fd, buf, result);
  close(fd);
  mq_unlink("/test.mq");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xa,-0x20(%rbp)
movl   $0x2000,-0x1c(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
lea    0xe58(%rip),%rdi
mov    $0x1b6,%edx
lea    -0x20(%rbp),%rcx
call   1050 <mq_open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1060 <mq_receive@plt>
mov    %eax,-0x2034(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
lea    0xe1b(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x2038(%rbp)
mov    -0x2038(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    -0x2034(%rbp),%edx
call   1030 <write@plt>
mov    -0x2038(%rbp),%edi
call   1040 <close@plt>
lea    0xdd8(%rip),%rdi
call   1080 <mq_unlink@plt>
xor    %eax,%eax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2018,%rsp
movq   $0x0,0x8(%rsp)
movabs $0x20000000000a,%rax
mov    %rax,(%rsp)
mov    0x2e55(%rip),%rax
mov    0x2e66(%rip),%rbx
mov    (%rbx),%esi
or     (%rax),%esi
lea    0xe63(%rip),%r14
mov    %rsp,%rcx
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1050 <mq_open@plt>
lea    0x10(%rsp),%r15
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x2000,%edx
xor    %ecx,%ecx
call   1060 <mq_receive@plt>
mov    %eax,%ebp
mov    0x2dfc(%rip),%rax
mov    (%rbx),%esi
or     (%rax),%esi
lea    0xe32(%rip),%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %r14,%rdi
call   1080 <mq_unlink@plt>
xor    %eax,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i64 }
@.str = [9 x i8] c"/test.mq\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [12 x i8] c"message.txt\00"
@O_WRONLY = global i32 0
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 [8192 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i32 0, i32 2
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i32 0, i32 0
store i32 10, i32* %12
%13 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i32 0, i32 1
store i32 8192, i32* %13
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = call i32 @mq_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16, i32 438, %struct.mq_attr* %6)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%20 = call i32 @mq_receive(i32 %18, i8* %19, i32 8192, i32 0)
store i32 %20, i32* %9
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %21, %22
%24 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 438)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* %9
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
%29 = load i32, i32* %10
%30 = call i32 @close(i32 %29)
%31 = call i32 @mq_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i64 }
@.str = [9 x i8] c"/test.mq\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [12 x i8] c"message.txt\00"
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.mq_attr
%4 = alloca [8192 x i8]
%5 = bitcast %struct.mq_attr* %3 to i8*
%6 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 2
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
store i32 10, i32* %7
%8 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 1
store i32 8192, i32* %8
%9 = load i32, i32* @O_RDONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = call i32 @mq_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 438, %struct.mq_attr* %3)
%13 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%14 = call i32 @mq_receive(i32 %12, i8* %13, i32 8192, i32 0)
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %16, %15
%18 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 438)
%19 = call i32 @write(i32 %18, i8* %13, i32 %14)
%20 = call i32 @close(i32 %18)
%21 = call i32 @mq_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
ret i32 0
}