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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
void *atol(char *);
int /*<<< orphan*/ bzero(struct mq_attr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int mq_open(char *, int, int, struct mq_attr *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  mqd_t mqd;
  struct mq_attr attr;
  bzero(&attr, sizeof(attr));
  attr.mq_maxmsg = atol(argv[2]);
  attr.mq_msgsize = atol(argv[3]);
  mqd = mq_open(argv[1], O_RDWR | O_CREAT,
                (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH),
                (attr.mq_maxmsg == 0) ? NULL : &attr);
  if (mqd == -1) {
    fprintf(stderr, "mq_open:%s\n", strerror(errno));
    perror("perror:");
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    0x2e26(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    0x2de9(%rip),%rcx
or     (%rcx),%eax
mov    0x2dc0(%rip),%rcx
or     (%rcx),%eax
mov    0x2ddf(%rip),%rcx
or     (%rcx),%eax
mov    0x2da6(%rip),%rcx
or     (%rcx),%eax
mov    0x2d85(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1226 <main+0xb6>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    1233 <main+0xc3>
lea    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1233 <main+0xc3>
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%esi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rcx
call   1040 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1292 <main+0x122>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xd86(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xd86(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    0x10(%r14),%rdi
call   1050 <atol@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
mov    0x18(%r14),%rdi
call   1050 <atol@plt>
mov    0x2e34(%rip),%rcx
mov    0x2e45(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    0x2de2(%rip),%rcx
mov    0x2e0b(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2de0(%rip),%rcx
or     (%rcx),%edx
mov    0x2dff(%rip),%rcx
or     (%rcx),%edx
mov    0x2dc6(%rip),%rcx
or     (%rcx),%edx
mov    %rax,0x8(%rsp)
mov    0x2da0(%rip),%rax
or     (%rax),%edx
mov    0x8(%r14),%rdi
test   %rbx,%rbx
cmove  %rbx,%r15
mov    %r15,%rcx
call   1040 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1216 <main+0xa6>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2da3(%rip),%rax
mov    (%rax),%ebx
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdcc(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
lea    0xdc7(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i64, i8* }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"mq_open:%s\0A\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"perror:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.mq_attr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @bzero(%struct.mq_attr* %7, i32 16)
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 2
%11 = load i8*, i8** %10
%12 = call i8* @atol(i8* %11)
%13 = ptrtoint i8* %12 to i64
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
store i64 %13, i64* %14
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 3
%17 = load i8*, i8** %16
%18 = call i8* @atol(i8* %17)
%19 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 1
store i8* %18, i8** %19
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IRGRP
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IWGRP
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IROTH
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IWOTH
%36 = or i32 %34, %35
%37 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%38 = load i64, i64* %37
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %2
br label %42
41: ; preds = %2
br label %42
42: ; preds = %41, %40
%43 = phi %struct.mq_attr* [ null, %40 ], [ %7, %41 ]
%44 = call i32 @mq_open(i8* %22, i32 %25, i32 %36, %struct.mq_attr* %43)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %50)
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %42
ret i32 0
}

LLVM IR (-O2):
%struct.mq_attr = type { i64, i8* }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"mq_open:%s\0A\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"perror:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.mq_attr
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = call i32 @bzero(%struct.mq_attr* %3, i32 16)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i8* @atol(i8* %7)
%9 = ptrtoint i8* %8 to i64
%10 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
store i64 %9, i64* %10
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i8* @atol(i8* %12)
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 1
store i8* %13, i8** %14
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = load i32, i32* @O_CREAT
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IRUSR
%21 = load i32, i32* @S_IWUSR
%22 = or i32 %21, %20
%23 = load i32, i32* @S_IRGRP
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IWGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IROTH
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IWOTH
%30 = or i32 %28, %29
%31 = icmp eq i8* %8, null
%32 = select i1 %31, %struct.mq_attr* null, %struct.mq_attr* %3
%33 = call i32 @mq_open(i8* %16, i32 %19, i32 %30, %struct.mq_attr* %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %2
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %2
ret i32 0
}