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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int getpid();
scalar_t__ mq_close(scalar_t__);
scalar_t__ mq_open(char *, int, int, struct mq_attr *);
int mq_receive(scalar_t__, char *, int, unsigned int *);
scalar_t__ mq_send(scalar_t__, char const *, int /*<<< orphan*/, int);
scalar_t__ mq_unlink(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
int main(void) {
  char mqname[50], msgrv1[40], msgrv2[40];
  const char *msgptr1 = "test message 1";
  const char *msgptr2 = "test message 2";
  mqd_t mqdes;
  unsigned rvprio;
  int sdprio1 = 1, sdprio2 = 2;
  struct mq_attr attr;
  int unresolved = 0, failure = 0;
  sprintf(mqname,
          "/"
          "mq_receive"
          "_"
          "1-1"
          "_%d",
          getpid());
  attr.mq_msgsize = 40;
  attr.mq_maxmsg = 40;
  mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
  if (mqdes == (mqd_t)-1) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_open");
    unresolved = 1;
  }
  if (mq_send(mqdes, msgptr1, strlen(msgptr1), sdprio1) != 0) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_send");
    unresolved = 1;
  }
  if (mq_send(mqdes, msgptr2, strlen(msgptr2), sdprio2) != 0) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_send");
    unresolved = 1;
  }
  if (mq_receive(mqdes, msgrv1, 40, &rvprio) == -1) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_receive");
    failure = 1;
  }
  if (strncmp(msgptr2, msgrv1, strlen(msgptr2)) != 0) {
    printf("FAIL: mq_receive didn't receive the highest priority message\n");
    failure = 1;
  }
  if ((int)rvprio != sdprio2) {
    printf("FAIL: receive priority %u != send priority %d\n", rvprio, sdprio2);
    failure = 1;
  }
  if (mq_receive(mqdes, msgrv2, 40, &rvprio) == -1) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_receive");
    failure = 1;
  }
  if (strncmp(msgptr1, msgrv2, strlen(msgptr1)) != 0) {
    printf("FAIL: mq_receive didn't receive the correct message\n");
    failure = 1;
  }
  if ((int)rvprio != sdprio1) {
    printf("FAIL: receive priority %u != send priority %d\n", rvprio, sdprio1);
    failure = 1;
  }
  if (mq_close(mqdes) != 0) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_close");
    unresolved = 1;
  }
  if (mq_unlink(mqname) != 0) {
    perror("unexpected error: "
           "mq_receive"
           " "
           "1-1"
           ": "
           "mq_unlink");
    unresolved = 1;
  }
  if (failure == 1) {
    printf("Test FAILED\n");
    return 1;
  }
  if (unresolved == 1) {
    printf("Test UNRESOLVED\n");
    return 2;
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe37(%rip),%rax
mov    %rax,-0xa8(%rbp)
lea    0xe38(%rip),%rax
mov    %rax,-0xb0(%rbp)
movl   $0x1,-0xc0(%rbp)
movl   $0x2,-0xc4(%rbp)
movl   $0x0,-0xd4(%rbp)
movl   $0x0,-0xd8(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0xe0(%rbp),%rdi
mov    %eax,%edx
lea    0xdf6(%rip),%rsi
call   10c0 <sprintf@plt>
movl   $0x28,-0xd0(%rbp)
movl   $0x28,-0xcc(%rbp)
lea    -0x40(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2d8b(%rip),%rax
or     (%rax),%esi
mov    0x2d6a(%rip),%rax
mov    (%rax),%edx
mov    0x2d71(%rip),%rax
or     (%rax),%edx
lea    -0xd0(%rbp),%rcx
call   1090 <mq_open@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0xffffffffffffffff,-0xb8(%rbp)
ff
jne    12a0 <main+0xf0>
lea    0xda0(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd4(%rbp)
mov    -0xb8(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xa8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xf0(%rbp),%rdi
mov    -0xe8(%rbp),%rsi
mov    %eax,%edx
mov    -0xc0(%rbp),%ecx
call   1080 <mq_send@plt>
cmp    $0x0,%rax
je     1303 <main+0x153>
lea    0xd67(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd4(%rbp)
mov    -0xb8(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0xb0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x100(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    %eax,%edx
mov    -0xc4(%rbp),%ecx
call   1080 <mq_send@plt>
cmp    $0x0,%rax
je     1366 <main+0x1b6>
lea    0xd04(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd4(%rbp)
mov    -0xb8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x28,%edx
lea    -0xbc(%rbp),%rcx
call   10a0 <mq_receive@plt>
cmp    $0xffffffff,%eax
jne    13a1 <main+0x1f1>
lea    0xcf3(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xb0(%rbp),%rax
mov    %rax,-0x110(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0xb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x110(%rbp),%rdi
mov    -0x108(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     13fd <main+0x24d>
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0xc4(%rbp),%eax
je     1433 <main+0x283>
mov    -0xbc(%rbp),%esi
mov    -0xc4(%rbp),%edx
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xb8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x28,%edx
lea    -0xbc(%rbp),%rcx
call   10a0 <mq_receive@plt>
cmp    $0xffffffff,%eax
jne    1471 <main+0x2c1>
lea    0xc23(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0xa8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x120(%rbp),%rdi
mov    -0x118(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     14d0 <main+0x320>
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0xc0(%rbp),%eax
je     1506 <main+0x356>
mov    -0xbc(%rbp),%esi
mov    -0xc0(%rbp),%edx
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0xd8(%rbp)
mov    -0xb8(%rbp),%rdi
call   1070 <mq_close@plt>
cmp    $0x0,%rax
je     1532 <main+0x382>
lea    0xc31(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd4(%rbp)
lea    -0x40(%rbp),%rdi
call   10d0 <mq_unlink@plt>
cmp    $0x0,%rax
je     155b <main+0x3ab>
lea    0xc33(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0xd4(%rbp)
cmpl   $0x1,-0xd8(%rbp)
jne    1582 <main+0x3d2>
lea    0xc3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15be <main+0x40e>
cmpl   $0x1,-0xd4(%rbp)
jne    15a9 <main+0x3f9>
lea    0xc22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15be <main+0x40e>
lea    0xc19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe40(%rip),%rsi
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10d0 <sprintf@plt>
movabs $0x2800000028,%rax
mov    %rax,0x8(%rsp)
mov    0x2df5(%rip),%rax
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2db3(%rip),%rax
mov    0x2dbc(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
call   10a0 <mq_open@plt>
mov    %rax,%r14
cmp    $0xffffffffffffffff,%rax
je     13e1 <main+0x221>
lea    0xdbf(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x1,%ecx
call   1090 <mq_send@plt>
test   %rax,%rax
jne    13f8 <main+0x238>
lea    0xda4(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x2,%ecx
call   1090 <mq_send@plt>
test   %rax,%rax
jne    140f <main+0x24f>
lea    0x40(%rsp),%rsi
lea    0x4(%rsp),%rcx
mov    %r14,%rdi
mov    $0x28,%edx
call   10b0 <mq_receive@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     1426 <main+0x266>
lea    0xd58(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12e4 <main+0x124>
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    0x4(%rsp),%esi
cmp    $0x2,%esi
je     1305 <main+0x145>
lea    0xdbe(%rip),%rdi
mov    $0x2,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebp
lea    0x10(%rsp),%rsi
lea    0x4(%rsp),%rcx
mov    %r14,%rdi
mov    $0x28,%edx
call   10b0 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     143c <main+0x27c>
lea    0xcd4(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1359 <main+0x199>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    0x4(%rsp),%esi
cmp    $0x1,%esi
je     137a <main+0x1ba>
lea    0xd49(%rip),%rdi
mov    $0x1,%ebp
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1080 <mq_close@plt>
test   %rax,%rax
jne    1452 <main+0x292>
lea    0x70(%rsp),%rdi
call   10e0 <mq_unlink@plt>
test   %rax,%rax
jne    1469 <main+0x2a9>
test   %ebp,%ebp
je     13b0 <main+0x1f0>
mov    $0x1,%ebx
lea    0xda6(%rip),%rdi
jmp    13cc <main+0x20c>
test   %r15d,%r15d
je     13c3 <main+0x203>
mov    $0x2,%ebx
lea    0xd83(%rip),%rdi
jmp    13cc <main+0x20c>
xor    %ebx,%ebx
lea    0xd6c(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc49(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r15d
jmp    123a <main+0x7a>
lea    0xc5c(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r15d
jmp    1264 <main+0xa4>
lea    0xc45(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r15d
jmp    128e <main+0xce>
lea    0xc58(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
jmp    12b0 <main+0xf0>
lea    0xc42(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
jmp    1325 <main+0x165>
lea    0xc88(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r15d
jmp    138b <main+0x1cb>
lea    0xc9c(%rip),%rdi
call   10c0 <perror@plt>
test   %ebp,%ebp
jne    13a2 <main+0x1e2>
jmp    13b5 <main+0x1f5>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32 }
@.str = [15 x i8] c"test message 1\00"
@.str.1 = [15 x i8] c"test message 2\00"
@.str.2 = [19 x i8] c"/mq_receive_1-1_%d\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.3 = [42 x i8] c"unexpected error: mq_receive 1-1: mq_open\00"
@.str.4 = [42 x i8] c"unexpected error: mq_receive 1-1: mq_send\00"
@.str.5 = [45 x i8] c"unexpected error: mq_receive 1-1: mq_receive\00"
@.str.6 = [62 x i8] c"FAIL: mq_receive didn't receive the highest priority message\0A\00"
@.str.7 = [47 x i8] c"FAIL: receive priority %u != send priority %d\0A\00"
@.str.8 = [53 x i8] c"FAIL: mq_receive didn't receive the correct message\0A\00"
@.str.9 = [43 x i8] c"unexpected error: mq_receive 1-1: mq_close\00"
@.str.10 = [44 x i8] c"unexpected error: mq_receive 1-1: mq_unlink\00"
@.str.11 = [13 x i8] c"Test FAILED\0A\00"
@.str.12 = [17 x i8] c"Test UNRESOLVED\0A\00"
@.str.13 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [40 x i8]
%4 = alloca [40 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.mq_attr
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i32 1, i32* %9
store i32 2, i32* %10
store i32 0, i32* %12
store i32 0, i32* %13
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%15 = call i32 (...) @getpid()
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %11, i32 0, i32 0
store i32 40, i32* %17
%18 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %11, i32 0, i32 1
store i32 40, i32* %18
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_RDWR
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRUSR
%24 = load i32, i32* @S_IWUSR
%25 = or i32 %23, %24
%26 = call i64 @mq_open(i8* %19, i32 %22, i32 %25, %struct.mq_attr* %11)
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = icmp eq i64 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %0
%30 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %12
br label %31
31: ; preds = %29, %0
%32 = load i64, i64* %7
%33 = load i8*, i8** %5
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
%36 = load i32, i32* %9
%37 = call i64 @mq_send(i64 %32, i8* %33, i32 %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %12
br label %41
41: ; preds = %39, %31
%42 = load i64, i64* %7
%43 = load i8*, i8** %6
%44 = load i8*, i8** %6
%45 = call i32 @strlen(i8* %44)
%46 = load i32, i32* %10
%47 = call i64 @mq_send(i64 %42, i8* %43, i32 %45, i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %41
%50 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %12
br label %51
51: ; preds = %49, %41
%52 = load i64, i64* %7
%53 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%54 = call i32 @mq_receive(i64 %52, i8* %53, i32 40, i32* %8)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %13
br label %58
58: ; preds = %56, %51
%59 = load i8*, i8** %6
%60 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%61 = load i8*, i8** %6
%62 = call i32 @strlen(i8* %61)
%63 = call i64 @strncmp(i8* %59, i8* %60, i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %58
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %13
br label %67
67: ; preds = %65, %58
%68 = load i32, i32* %8
%69 = load i32, i32* %10
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load i32, i32* %8
%73 = load i32, i32* %10
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %72, i32 %73)
store i32 1, i32* %13
br label %75
75: ; preds = %71, %67
%76 = load i64, i64* %7
%77 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%78 = call i32 @mq_receive(i64 %76, i8* %77, i32 40, i32* %8)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %13
br label %82
82: ; preds = %80, %75
%83 = load i8*, i8** %5
%84 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%85 = load i8*, i8** %5
%86 = call i32 @strlen(i8* %85)
%87 = call i64 @strncmp(i8* %83, i8* %84, i32 %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %82
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %13
br label %91
91: ; preds = %89, %82
%92 = load i32, i32* %8
%93 = load i32, i32* %9
%94 = icmp ne i32 %92, %93
br i1 %94, label %95, label %99
95: ; preds = %91
%96 = load i32, i32* %8
%97 = load i32, i32* %9
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %96, i32 %97)
store i32 1, i32* %13
br label %99
99: ; preds = %95, %91
%100 = load i64, i64* %7
%101 = call i64 @mq_close(i64 %100)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %99
%104 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %12
br label %105
105: ; preds = %103, %99
%106 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%107 = call i64 @mq_unlink(i8* %106)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %105
%110 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %12
br label %111
111: ; preds = %109, %105
%112 = load i32, i32* %13
%113 = icmp eq i32 %112, 1
br i1 %113, label %114, label %116
114: ; preds = %111
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %1
br label %123
116: ; preds = %111
%117 = load i32, i32* %12
%118 = icmp eq i32 %117, 1
br i1 %118, label %119, label %121
119: ; preds = %116
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0))
store i32 2, i32* %1
br label %123
121: ; preds = %116
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %1
br label %123
123: ; preds = %121, %119, %114
%124 = load i32, i32* %1
ret i32 %124
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32 }
@.str = [15 x i8] c"test message 1\00"
@.str.1 = [15 x i8] c"test message 2\00"
@.str.2 = [19 x i8] c"/mq_receive_1-1_%d\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.3 = [42 x i8] c"unexpected error: mq_receive 1-1: mq_open\00"
@.str.4 = [42 x i8] c"unexpected error: mq_receive 1-1: mq_send\00"
@.str.5 = [45 x i8] c"unexpected error: mq_receive 1-1: mq_receive\00"
@.str.7 = [47 x i8] c"FAIL: receive priority %u != send priority %d\0A\00"
@.str.9 = [43 x i8] c"unexpected error: mq_receive 1-1: mq_close\00"
@.str.10 = [44 x i8] c"unexpected error: mq_receive 1-1: mq_unlink\00"
@str = [12 x i8] c"Test PASSED\00"
@str.14 = [16 x i8] c"Test UNRESOLVED\00"
@str.15 = [12 x i8] c"Test FAILED\00"
@str.16 = [52 x i8] c"FAIL: mq_receive didn't receive the correct message\00"
@str.17 = [61 x i8] c"FAIL: mq_receive didn't receive the highest priority message\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = alloca i32
%5 = alloca %struct.mq_attr
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
%10 = bitcast %struct.mq_attr* %5 to i8*
%11 = tail call i32 (...) @getpid()
%12 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %5, i64 0, i32 0
store i32 40, i32* %13
%14 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %5, i64 0, i32 1
store i32 40, i32* %14
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_RDWR
%17 = or i32 %16, %15
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IWUSR
%20 = or i32 %19, %18
%21 = call i64 @mq_open(i8* %6, i32 %17, i32 %20, %struct.mq_attr* %5)
%22 = icmp eq i64 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %0
%26 = phi i32 [ 1, %23 ], [ 0, %0 ]
%27 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%28 = call i64 @mq_send(i64 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %27, i32 1)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = phi i32 [ 1, %30 ], [ %26, %25 ]
%34 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%35 = call i64 @mq_send(i64 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 2)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %37, %32
%40 = phi i32 [ 1, %37 ], [ %33, %32 ]
%41 = call i32 @mq_receive(i64 %21, i8* %7, i32 40, i32* %4)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = phi i32 [ 1, %43 ], [ 0, %39 ]
%47 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%48 = call i64 @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %45
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.17, i64 0, i64 0))
br label %52
52: ; preds = %50, %45
%53 = phi i32 [ 1, %50 ], [ %46, %45 ]
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 2
br i1 %55, label %58, label %56
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %54, i32 2)
br label %58
58: ; preds = %56, %52
%59 = phi i32 [ 1, %56 ], [ %53, %52 ]
%60 = call i32 @mq_receive(i64 %21, i8* %8, i32 40, i32* %4)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %62, %58
%65 = phi i32 [ 1, %62 ], [ %59, %58 ]
%66 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%67 = call i64 @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %71, label %69
69: ; preds = %64
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.16, i64 0, i64 0))
br label %71
71: ; preds = %69, %64
%72 = phi i32 [ 1, %69 ], [ %65, %64 ]
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 1
br i1 %74, label %77, label %75
75: ; preds = %71
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %73, i32 1)
br label %77
77: ; preds = %75, %71
%78 = phi i32 [ 1, %75 ], [ %72, %71 ]
%79 = call i64 @mq_close(i64 %21)
%80 = icmp eq i64 %79, 0
br i1 %80, label %83, label %81
81: ; preds = %77
%82 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
br label %83
83: ; preds = %81, %77
%84 = phi i32 [ 1, %81 ], [ %40, %77 ]
%85 = call i64 @mq_unlink(i8* %6)
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = icmp eq i32 %78, 1
br i1 %88, label %95, label %92
89: ; preds = %83
%90 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0))
%91 = icmp eq i32 %78, 1
br i1 %91, label %95, label %94
92: ; preds = %87
%93 = icmp eq i32 %84, 1
br i1 %93, label %94, label %95
94: ; preds = %89, %92
br label %95
95: ; preds = %92, %87, %89, %94
%96 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.14, i64 0, i64 0), %94 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0), %89 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0), %87 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), %92 ]
%97 = phi i32 [ 2, %94 ], [ 1, %89 ], [ 1, %87 ], [ 0, %92 ]
%98 = call i32 @puts(i8* dereferenceable(1) %96)
ret i32 %97
}