#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 scalar_t__ mqd_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
scalar_t__ mq_open(char *, int, int, struct mq_attr *);
int /*<<< orphan*/ perror(char *);
int main() {
  mqd_t mqd;
  struct mq_attr attr;
  attr.mq_maxmsg = 50;
  attr.mq_msgsize = 2048;
  mqd = mq_open("/mymq", O_RDWR | O_CREAT, 666, &attr);
  if (mqd == (mqd_t)-1)
    perror("mq_open");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x32,-0x18(%rbp)
movl   $0x800,-0x14(%rbp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    0x2eab(%rip),%rax
or     (%rax),%esi
lea    0xeaa(%rip),%rdi
mov    $0x29a,%edx
lea    -0x18(%rbp),%rcx
call   1030 <mq_open@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    117f <main+0x5f>
lea    0xe8c(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movabs $0x80000000032,%rax
mov    %rax,(%rsp)
mov    0x2eaa(%rip),%rax
mov    0x2ebb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb8(%rip),%rdi
mov    %rsp,%rcx
mov    $0x29a,%edx
call   1030 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     115f <main+0x3f>
xor    %eax,%eax
pop    %rcx
ret
lea    0xea0(%rip),%rdi
call   1040 <perror@plt>
jmp    115b <main+0x3b>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32 }
@.str = [6 x i8] c"/mymq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [8 x i8] c"mq_open\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.mq_attr
store i32 0, i32* %1
%4 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 0
store i32 50, i32* %4
%5 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 1
store i32 2048, i32* %5
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = call i64 @mq_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8, i32 666, %struct.mq_attr* %3)
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
ret i32 0
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32 }
@.str = [6 x i8] c"/mymq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [8 x i8] c"mq_open\00"
define i32 @main() {
%1 = alloca %struct.mq_attr
%2 = bitcast %struct.mq_attr* %1 to i8*
%3 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 0
store i32 50, i32* %3
%4 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 1
store i32 2048, i32* %4
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = call i64 @mq_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7, i32 666, %struct.mq_attr* %1)
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
ret i32 0
}