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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int mq_open(char *, int /*<<< orphan*/);
scalar_t__ mq_receive(int, char *, int, unsigned int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  mqd_t mq;
  unsigned int priority;
  char buffer[8192];
  if (argc != 2) {
    fprintf(stderr, "usage: %s mq_name\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  mq = mq_open(argv[1], O_RDONLY);
  if (mq == -1) {
    perror(argv[1]);
    exit(EXIT_FAILURE);
  }
  if (mq_receive(mq, buffer, 8192, &priority) < 0) {
    perror("mq_send");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "[%d] %s\n", priority, buffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x4f>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   1040 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11dd <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
lea    -0x18(%rbp),%rcx
call   1050 <mq_receive@plt>
cmp    $0x0,%rax
jge    1219 <main+0xc9>
lea    0xe0d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    -0x2020(%rbp),%rcx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x2010,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11c4 <main+0x74>
mov    0x8(%rbx),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1040 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0x90>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    %eax,%edi
mov    $0x2000,%edx
call   1050 <mq_receive@plt>
test   %rax,%rax
js     11e6 <main+0x96>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
lea    0xe75(%rip),%rsi
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
add    $0x2010,%rsp
pop    %rbx
ret
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe29(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f2 <main+0xa2>
mov    0x8(%rbx),%rdi
jmp    11ed <main+0x9d>
lea    0xe26(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s mq_name\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"mq_send\00"
@stdout = global i32 0
@.str.2 = [9 x i8] c"[%d] %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 i32
%8 = alloca [8192 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @mq_open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @perror(i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %19
%35 = load i32, i32* %6
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%37 = call i64 @mq_receive(i32 %35, i8* %36, i32 8192, i32* %7)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = load i32, i32* @stdout
%45 = load i32, i32* %7
%46 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %45, i8* %46)
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s mq_name\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"mq_send\00"
@stdout = global i32 0
@.str.2 = [9 x i8] c"[%d] %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [8192 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @mq_open(i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i8*, i8** %15
%22 = tail call i32 @perror(i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = call i64 @mq_receive(i32 %18, i8* %6, i32 8192, i32* %3)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %25
%33 = load i32, i32* @stdout
%34 = load i32, i32* %3
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %6)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}