#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_curmsgs;
  scalar_t__ mq_flags;
};
typedef scalar_t__ mqd_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRWXG;
int S_IRWXU;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ mq_getattr(scalar_t__, struct mq_attr *);
scalar_t__ mq_open(char const *, int, int, struct mq_attr *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void setup_mbox(mqd_t *mbox, struct mq_attr *attr, const char *name) {
  attr->mq_flags = 0;
  attr->mq_maxmsg = 10;
  attr->mq_msgsize = 4;
  attr->mq_curmsgs = 0;
  *mbox = mq_open(name, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG, attr);
  if (*mbox == (mqd_t)-1) {
    perror("mq_open");
    fprintf(stderr, "-- unable to create mbox '%s'", name);
  }
  mq_getattr(*mbox, attr);
}


x86 assembly (clang, -O0):
<setup_mbox>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e63(%rip),%rax
or     (%rax),%esi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    0x2e29(%rip),%rax
or     (%rax),%edx
mov    -0x10(%rbp),%rcx
call   1040 <mq_open@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
jne    11ef <setup_mbox+0xaf>
lea    0xe2f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe1e(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <mq_getattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_mbox>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
movabs $0x40000000a,%rax
mov    %rax,(%rsi)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsi)
mov    0x2e6f(%rip),%rax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e65(%rip),%rax
mov    0x2e4e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1040 <mq_open@plt>
mov    %rax,(%r14)
cmp    $0xffffffffffffffff,%rax
je     11aa <setup_mbox+0x6a>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <mq_getattr@plt>
lea    0xe4f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    %r15,%rdx
call   1030 <fprintf@plt>
mov    (%r14),%rax
jmp    119a <setup_mbox+0x5a>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i64, i64 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@.str = [8 x i8] c"mq_open\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"-- unable to create mbox '%s'\00"
define void @setup_mbox(i64* %0, %struct.mq_attr* %1, i8* %2) {
%4 = alloca i64*
%5 = alloca %struct.mq_attr*
%6 = alloca i8*
store i64* %0, i64** %4
store %struct.mq_attr* %1, %struct.mq_attr** %5
store i8* %2, i8** %6
%7 = load %struct.mq_attr*, %struct.mq_attr** %5
%8 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 3
store i64 0, i64* %8
%9 = load %struct.mq_attr*, %struct.mq_attr** %5
%10 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %9, i32 0, i32 0
store i32 10, i32* %10
%11 = load %struct.mq_attr*, %struct.mq_attr** %5
%12 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %11, i32 0, i32 1
store i32 4, i32* %12
%13 = load %struct.mq_attr*, %struct.mq_attr** %5
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %13, i32 0, i32 2
store i64 0, i64* %14
%15 = load i8*, i8** %6
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRWXU
%20 = load i32, i32* @S_IRWXG
%21 = or i32 %19, %20
%22 = load %struct.mq_attr*, %struct.mq_attr** %5
%23 = call i64 @mq_open(i8* %15, i32 %18, i32 %21, %struct.mq_attr* %22)
%24 = load i64*, i64** %4
store i64 %23, i64* %24
%25 = load i64*, i64** %4
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %3
%29 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %3
%34 = load i64*, i64** %4
%35 = load i64, i64* %34
%36 = load %struct.mq_attr*, %struct.mq_attr** %5
%37 = call i32 @mq_getattr(i64 %35, %struct.mq_attr* %36)
ret void
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i64, i64 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@.str = [8 x i8] c"mq_open\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"-- unable to create mbox '%s'\00"
define void @setup_mbox(i64* nocapture %0, %struct.mq_attr* %1, i8* %2) {
%4 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 0
store i32 10, i32* %4
%5 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 1
store i32 4, i32* %5
%6 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 2
%7 = bitcast i64* %6 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %7
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IRWXU
%12 = load i32, i32* @S_IRWXG
%13 = or i32 %12, %11
%14 = tail call i64 @mq_open(i8* %2, i32 %10, i32 %13, %struct.mq_attr* %1)
store i64 %14, i64* %0
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%20 = load i64, i64* %0
br label %21
21: ; preds = %16, %3
%22 = phi i64 [ %20, %16 ], [ %14, %3 ]
%23 = tail call i32 @mq_getattr(i64 %22, %struct.mq_attr* %1)
ret void
}