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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mq_getattr(int /*<<< orphan*/, struct mq_attr *);
int mq_receive(int /*<<< orphan*/, char *, int /*<<< orphan*/,
               int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int my_mq_receive(mqd_t mq, void *buffer) {
  int res;
  struct mq_attr attr;
  mq_getattr(mq, &attr);
  res = mq_receive(mq, (char *)buffer, attr.mq_msgsize, NULL);
  if (res == -1) {
    perror("mq_receive");
    exit(1);
  }
  return res;
}


x86 assembly (clang, -O0):
<my_mq_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <mq_getattr@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <mq_receive@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1191 <my_mq_receive+0x51>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_mq_receive>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rsi
call   1060 <mq_getattr@plt>
mov    (%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1030 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     116b <my_mq_receive+0x2b>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32 }
@.str = [11 x i8] c"mq_receive\00"
define i32 @my_mq_receive(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.mq_attr
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = call i32 @mq_getattr(i32 %7, %struct.mq_attr* %6)
%9 = load i32, i32* %3
%10 = load i8*, i8** %4
%11 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @mq_receive(i32 %9, i8* %10, i32 %12, i32* null)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* %5
ret i32 %20
}

LLVM IR (-O2):
%struct.mq_attr = type { i32 }
@.str = [11 x i8] c"mq_receive\00"
define i32 @my_mq_receive(i32 %0, i8* %1) {
%3 = alloca %struct.mq_attr
%4 = bitcast %struct.mq_attr* %3 to i8*
%5 = call i32 @mq_getattr(i32 %0, %struct.mq_attr* %3)
%6 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = call i32 @mq_receive(i32 %0, i8* %1, i32 %7, i32* null)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
ret i32 %8
}