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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int mq_getattr(int, struct mq_attr *);
int mq_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int r;
  mqd_t mqd;
  struct mq_attr attr;
  mqd = mq_open(argv[1], O_RDONLY);
  if (mqd == -1) {
    fprintf(stderr, "mq_open:%s\n", strerror(errno));
    exit(-1);
  }
  r = mq_getattr(mqd, &attr);
  if (r == -1) {
    fprintf(stderr, "mq_getattr:%s\n", strerror(errno));
    exit(-1);
  }
  printf("mq_flags:%ld,mq_maxmsg:%ld,mq_msgsize:%ld,mq_curmsgs:%ld\n",
         attr.mq_flags, attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1050 <mq_open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11cf <main+0x6f>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1080 <mq_getattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    121e <main+0xbe>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xdfd(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xde9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11af <main+0x4f>
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <mq_getattr@plt>
cmp    $0xffffffff,%eax
je     11cf <main+0x6f>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    (%rsp),%r8d
mov    0x4(%rsp),%ecx
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e22(%rip),%rax
mov    (%rax),%ebx
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe33(%rip),%rsi
jmp    11ed <main+0x8d>
mov    0x2e02(%rip),%rax
mov    (%rax),%ebx
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32, i32 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"mq_open:%s\0A\00"
@errno = global i32 0
@.str.1 = [15 x i8] c"mq_getattr:%s\0A\00"
@.str.2 = [58 x i8] c"mq_flags:%ld,mq_maxmsg:%ld,mq_msgsize:%ld,mq_curmsgs:%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.mq_attr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @mq_open(i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = load i32, i32* %7
%24 = call i32 @mq_getattr(i32 %23, %struct.mq_attr* %8)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %22
%34 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %8, i32 0, i32 3
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %8, i32 0, i32 2
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %8, i32 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %8, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %37, i32 %39, i32 %41)
ret i32 0
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32, i32 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"mq_open:%s\0A\00"
@errno = global i32 0
@.str.1 = [15 x i8] c"mq_getattr:%s\0A\00"
@.str.2 = [58 x i8] c"mq_flags:%ld,mq_maxmsg:%ld,mq_msgsize:%ld,mq_curmsgs:%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.mq_attr
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @mq_open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i32 @mq_getattr(i32 %8, %struct.mq_attr* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %16
%26 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 2
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %29, i32 %31, i32 %33)
ret i32 0
}