#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;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ mqd_t;

/* Variables and functions */
scalar_t__ mq_getattr(int /*<<< orphan*/, struct mq_attr *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int mq_status(mqd_t mqd) {
  struct mq_attr attr = {0};
  if (mq_getattr(mqd, &attr) < 0) {
    perror("mq_getattr");
  }
  printf("----status---\n");
  printf("mq_flags = %ld\n", attr.mq_flags);
  printf("mq_maxmsg = %ld\n", attr.mq_maxmsg);
  printf("mq_msgsize = %ld\n", attr.mq_msgsize);
  printf("mq_curmsgs = %ld\n", attr.mq_curmsgs);
  printf("----status end----\n");
  return 0;
}


x86 assembly (clang, -O0):
<mq_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <mq_getattr@plt>
cmp    $0x0,%rax
jge    117d <mq_status+0x3d>
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mq_status>:
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%rsi
call   1060 <mq_getattr@plt>
test   %rax,%rax
js     11c6 <mq_status+0x86>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe33(%rip),%rdi
call   1050 <perror@plt>
jmp    1160 <mq_status+0x20>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32, i32, i32 }
@.str = [11 x i8] c"mq_getattr\00"
@.str.1 = [15 x i8] c"----status---\0A\00"
@.str.2 = [16 x i8] c"mq_flags = %ld\0A\00"
@.str.3 = [17 x i8] c"mq_maxmsg = %ld\0A\00"
@.str.4 = [18 x i8] c"mq_msgsize = %ld\0A\00"
@.str.5 = [18 x i8] c"mq_curmsgs = %ld\0A\00"
@.str.6 = [20 x i8] c"----status end----\0A\00"
define i32 @mq_status(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.mq_attr
store i32 %0, i32* %2
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = load i32, i32* %2
%6 = call i64 @mq_getattr(i32 %5, %struct.mq_attr* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 3
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 2
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32, i32, i32 }
@.str = [11 x i8] c"mq_getattr\00"
@.str.2 = [16 x i8] c"mq_flags = %ld\0A\00"
@.str.3 = [17 x i8] c"mq_maxmsg = %ld\0A\00"
@.str.4 = [18 x i8] c"mq_msgsize = %ld\0A\00"
@.str.5 = [18 x i8] c"mq_curmsgs = %ld\0A\00"
@str = [14 x i8] c"----status---\00"
@str.7 = [19 x i8] c"----status end----\00"
define i32 @mq_status(i32 %0) {
%2 = alloca %struct.mq_attr
%3 = bitcast %struct.mq_attr* %2 to i8*
%4 = call i64 @mq_getattr(i32 %0, %struct.mq_attr* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 3
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 2
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 1
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}