#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_flags;
  int mq_maxmsg;
  int mq_msgsize;
  int mq_curmsgs;
};
typedef int mqd_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ mq_getattr(int, struct mq_attr *);
int mq_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  mqd_t mqd;
  struct mq_attr obuf;
  if (argc < 2) {
    printf("A pathname of a message queue is required\n");
    return -1;
  }
  mqd = mq_open(argv[1], O_RDONLY);
  if (-1 != mqd) {
    if (!mq_getattr(mqd, &obuf)) {
      printf("flags: 0x%x  maxmsg: %d  msgsize: %d  curmsgs: %d\n",
             obuf.mq_flags, obuf.mq_maxmsg, obuf.mq_msgsize, obuf.mq_curmsgs);
    } else
      perror("mq_getattr()");
  } else
    perror("mq_open()");
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1040 <mq_open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
je     11e7 <main+0xa7>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <mq_getattr@plt>
cmp    $0x0,%eax
jne    11d6 <main+0x96>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e2 <main+0xa2>
lea    0xe81(%rip),%rdi
call   1050 <perror@plt>
jmp    11f3 <main+0xb3>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     116d <main+0x1d>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11b2 <main+0x62>
mov    0x8(%rsi),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11ba <main+0x6a>
mov    %rsp,%rsi
mov    %eax,%edi
call   1070 <mq_getattr@plt>
test   %eax,%eax
jne    11c3 <main+0x73>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xe57(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7f(%rip),%rdi
jmp    11ca <main+0x7a>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
xor    %ebx,%ebx
jmp    11b2 <main+0x62>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32, i32 }
@.str = [43 x i8] c"A pathname of a message queue is required\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [51 x i8] c"flags: 0x%x maxmsg: %d msgsize: %d curmsgs: %d\0A\00"
@.str.2 = [13 x i8] c"mq_getattr()\00"
@.str.3 = [10 x i8] c"mq_open()\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 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @mq_open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 -1, %18
br i1 %19, label %20, label %37
20: ; preds = %12
%21 = load i32, i32* %6
%22 = call i32 @mq_getattr(i32 %21, %struct.mq_attr* %7)
%23 = icmp ne i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %20
%25 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 2
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 3
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %28, i32 %30, i32 %32)
br label %36
34: ; preds = %20
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %24
br label %39
37: ; preds = %12
%38 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %10, %37, %36
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32, i32 }
@O_RDONLY = global i32 0
@.str.1 = [51 x i8] c"flags: 0x%x maxmsg: %d msgsize: %d curmsgs: %d\0A\00"
@.str.2 = [13 x i8] c"mq_getattr()\00"
@.str.3 = [10 x i8] c"mq_open()\00"
@str = [42 x i8] c"A pathname of a message queue is required\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.mq_attr
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @mq_open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %29, label %14
14: ; preds = %8
%15 = call i32 @mq_getattr(i32 %12, %struct.mq_attr* %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 3
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21, i32 %23, i32 %25)
br label %31
27: ; preds = %14
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %31
29: ; preds = %8
%30 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %27, %17, %6
%32 = phi i32 [ -1, %6 ], [ 0, %17 ], [ 0, %27 ], [ 0, %29 ]
ret i32 %32
}