#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;
};
typedef int mqd_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mq_close(int);
int mq_getattr(int, struct mq_attr *);
int mq_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  mqd_t mqd;
  struct mq_attr attr;
  if (argc != 2) {
    printf("usage: %s  <name>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (-1 == (mqd = mq_open(argv[1], O_RDONLY))) {
    printf("mq_open error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (-1 == mq_getattr(mqd, &attr)) {
    printf("mq_getattr error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("maxmsg = %ld, msgsize = %ld, curmsgs = %ld\n", attr.mq_maxmsg,
         attr.mq_msgsize, attr.mq_curmsgs);
  if (-1 == mq_close(mqd)) {
    printf("mq_close error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1050 <mq_open@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f8 <main+0x98>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <mq_getattr@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1240 <main+0xe0>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movslq -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <mq_close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    129c <main+0x13c>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1198 <main+0x38>
mov    0x8(%rsi),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
jne    11a4 <main+0x44>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe7d(%rip),%rdi
jmp    1207 <main+0xa7>
mov    (%rsi),%rsi
lea    0xe5e(%rip),%rdi
jmp    120a <main+0xaa>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <mq_getattr@plt>
cmp    $0xffffffff,%eax
jne    11cc <main+0x6c>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe5c(%rip),%rdi
jmp    1207 <main+0xa7>
movslq 0x8(%rsp),%rsi
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <mq_close@plt>
cmp    $0xffffffff,%eax
jne    121f <main+0xbf>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe61(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32 }
@.str = [19 x i8] c"usage: %s <name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"mq_open error: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"mq_getattr error: %s\0A\00"
@.str.3 = [44 x i8] c"maxmsg = %ld, msgsize = %ld, curmsgs = %ld\0A\00"
@.str.4 = [20 x i8] c"mq_close error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
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 ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @mq_open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp eq i32 -1, %22
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %17
%31 = load i32, i32* %6
%32 = call i32 @mq_getattr(i32 %31, %struct.mq_attr* %7)
%33 = icmp eq i32 -1, %32
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
%41 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 2
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i8*
%45 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 1
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %7, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %46, i32 %48)
%50 = load i32, i32* %6
%51 = call i32 @mq_close(i32 %50)
%52 = icmp eq i32 -1, %51
br i1 %52, label %53, label %59
53: ; preds = %40
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %40
%60 = load i32, i32* @EXIT_SUCCESS
%61 = call i32 @exit(i32 %60)
unreachable
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32 }
@.str = [19 x i8] c"usage: %s <name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"mq_open error: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"mq_getattr error: %s\0A\00"
@.str.3 = [44 x i8] c"maxmsg = %ld, msgsize = %ld, curmsgs = %ld\0A\00"
@.str.4 = [20 x i8] c"mq_close error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.mq_attr
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @mq_open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %11
%24 = call i32 @mq_getattr(i32 %15, %struct.mq_attr* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %23
%33 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 2
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %36, i32 %38, i32 %40)
%42 = call i32 @mq_close(i32 %15)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %32
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %32
%51 = load i32, i32* @EXIT_SUCCESS
%52 = call i32 @exit(i32 %51)
unreachable
}