#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 O_NONBLOCK;
int O_RDONLY;
int errno;
int /*<<< orphan*/ mq_close(int);
int mq_open(char *, int);
int mq_receive(int, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  mqd_t fd;
  int size;
  char buffer[20];
  if (argc != 2) {
    printf("usage: %s </mqueue name> \n", argv[0]);
    return 2;
  }
  fd = mq_open(argv[1], O_RDONLY | O_NONBLOCK);
  if (fd == -1) {
    printf("mqrcv: mq_open: errno = %d\n", errno);
    return 2;
  }
  size = mq_receive(fd, buffer, 20, NULL);
  if (size == -1) {
    printf("mqrcv: mq_receive: errno = %d\n", errno);
    return 2;
  }
  mq_close(fd);
  return 0;
}


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)
je     1181 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1224 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e4f(%rip),%rax
or     (%rax),%esi
call   1050 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d0 <main+0x90>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1224 <main+0xe4>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <mq_receive@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1215 <main+0xd5>
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1224 <main+0xe4>
mov    -0x14(%rbp),%edi
call   1040 <mq_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    118e <main+0x4e>
mov    0x8(%rsi),%rdi
mov    0x2e8a(%rip),%rax
mov    0x2e8b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11a1 <main+0x61>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x14,%edx
xor    %ecx,%ecx
call   1060 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     11b3 <main+0x73>
mov    %ebp,%edi
call   1040 <mq_close@plt>
jmp    11cf <main+0x8f>
mov    (%rsi),%rsi
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11ca <main+0x8a>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
jmp    11c3 <main+0x83>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"usage: %s </mqueue name> \0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [28 x i8] c"mqrcv: mq_open: errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [31 x i8] c"mqrcv: mq_receive: errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 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 %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 2, i32* %3
br label %41
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = load i32, i32* @O_NONBLOCK
%22 = or i32 %20, %21
%23 = call i32 @mq_open(i8* %19, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %16
%27 = load i32, i32* @errno
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %27)
store i32 2, i32* %3
br label %41
29: ; preds = %16
%30 = load i32, i32* %6
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%32 = call i32 @mq_receive(i32 %30, i8* %31, i32 20, i32* null)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* @errno
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 2, i32* %3
br label %41
38: ; preds = %29
%39 = load i32, i32* %6
%40 = call i32 @mq_close(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %35, %26, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [27 x i8] c"usage: %s </mqueue name> \0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [28 x i8] c"mqrcv: mq_open: errno = %d\0A\00"
@errno = global i32 0
@.str.2 = [31 x i8] c"mqrcv: mq_receive: errno = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %28
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = load i32, i32* @O_NONBLOCK
%14 = or i32 %13, %12
%15 = tail call i32 @mq_open(i8* %11, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = load i32, i32* @errno
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %28
20: ; preds = %9
%21 = call i32 @mq_receive(i32 %15, i8* %4, i32 20, i32* null)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @errno
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %20
%27 = call i32 @mq_close(i32 %15)
br label %28
28: ; preds = %26, %23, %17, %6
%29 = phi i32 [ 2, %6 ], [ 2, %17 ], [ 2, %23 ], [ 0, %26 ]
ret i32 %29
}