#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_maxmsg;
  int mq_msgsize;
  scalar_t__ mq_curmsgs;
  scalar_t__ mq_flags;
};
typedef int ssize_t;
typedef scalar_t__ mqd_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ ENOSYS;
scalar_t__ EPERM;
int O_CREAT;
int O_EXCL;
int O_NONBLOCK;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ dump_mqueue_state(char const *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ mq_close(scalar_t__);
int mq_getattr(scalar_t__, struct mq_attr *);
scalar_t__ mq_open(char const *, int, ...);
int mq_receive(scalar_t__, char *, size_t, unsigned int *);
int mq_send(scalar_t__, char const *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mq_unlink(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char **argv) {
  mqd_t mqdes;
  const char *queue_name = "/test_message_queue";
  const char *message_text;
  char buffer[4096];
  struct mq_attr attr;
  ssize_t recv_size;
  unsigned int prio;
  int retval = 1;
  if (argc >= 2) {
    queue_name = argv[1];
  }
  attr.mq_flags = 0;
  attr.mq_maxmsg = 10;
  attr.mq_msgsize = sizeof(buffer);
  attr.mq_curmsgs = 0;
  mqdes = mq_open(queue_name, O_WRONLY | O_CREAT | O_EXCL, 0600, &attr);
  if (mqdes == (mqd_t)-1) {
    if (errno == ENOSYS) {
      fprintf(stderr, "Exit because the kernel does not support mq_open.\n");
      exit(0);
    }
    perror("mq_open");
    if (queue_name[0] != '/') {
      fprintf(stderr, "It seems that the initial '/' is missing.\n");
    }
    return 1;
  }
  message_text = "Hello, world!";
  if (mq_send(mqdes, message_text, strlen(message_text), 1) == -1) {
    if (errno == EPERM) {
      printf("mq_send() is denied, exiting.\n");
      retval = 0;
      goto cleanup;
    }
    perror("mq_send");
    goto cleanup;
  }
  message_text = "The answer is 42.";
  if (mq_send(mqdes, message_text, strlen(message_text), 42) == -1) {
    perror("mq_send");
    goto cleanup;
  }
  mq_close(mqdes);
  mqdes = (mqd_t)-1;
  dump_mqueue_state(queue_name);
  mqdes = mq_open(queue_name, O_RDONLY | O_NONBLOCK);
  if (mqdes == (mqd_t)-1) {
    perror("mq_open");
    goto cleanup;
  }
  if (mq_getattr(mqdes, &attr) == -1) {
    perror("mq_getattr");
    goto cleanup;
  }
  assert((size_t)attr.mq_msgsize <= sizeof(buffer));
  assert(attr.mq_curmsgs >= 0);
  if (attr.mq_curmsgs == 0) {
    printf("There is no message in the queue. It has disappeared!\n");
    goto cleanup;
  }
  while (--attr.mq_curmsgs >= 0) {
    recv_size = mq_receive(mqdes, buffer, (size_t)attr.mq_msgsize, &prio);
    if (recv_size == -1) {
      perror("mq_receive");
      goto cleanup;
    }
    assert(recv_size >= 0 && (size_t)recv_size < sizeof(buffer));
    buffer[recv_size] = '\0';
    printf("Received message with prio %u: %s\n", prio, buffer);
  }
  retval = 0;
cleanup:
  if (mqdes != (mqd_t)-1) {
    mq_close(mqdes);
  }
  mq_unlink(queue_name);
  return retval;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1080,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x1054(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1214 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x1038(%rbp)
movl   $0xa,-0x1048(%rbp)
movl   $0x1000,-0x1044(%rbp)
movq   $0x0,-0x1040(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    0x2da6(%rip),%rax
or     (%rax),%esi
mov    0x2d5d(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
lea    -0x1048(%rbp),%rcx
mov    $0x0,%al
call   1090 <mq_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    12f2 <main+0x122>
mov    0x2d2a(%rip),%rax
mov    (%rax),%rax
mov    0x2d40(%rip),%rcx
cmp    (%rcx),%rax
jne    12b5 <main+0xe5>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd8b(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     12e6 <main+0x116>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b3 <main+0x3e3>
lea    0xd81(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1068(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1068(%rbp),%rdi
mov    -0x1060(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%ecx
call   1060 <mq_send@plt>
cmp    $0xffffffff,%eax
jne    1387 <main+0x1b7>
mov    0x2c6a(%rip),%rax
mov    (%rax),%rax
mov    0x2c48(%rip),%rcx
cmp    (%rcx),%rax
jne    1376 <main+0x1a6>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1054(%rbp)
jmp    158d <main+0x3bd>
lea    0xd2a(%rip),%rdi
call   10b0 <perror@plt>
jmp    158d <main+0x3bd>
lea    0xd21(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1078(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x1070(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1078(%rbp),%rdi
mov    -0x1070(%rbp),%rsi
mov    %eax,%edx
mov    $0x2a,%ecx
call   1060 <mq_send@plt>
cmp    $0xffffffff,%eax
jne    13e5 <main+0x215>
lea    0xccc(%rip),%rdi
call   10b0 <perror@plt>
jmp    158d <main+0x3bd>
mov    -0x18(%rbp),%rdi
call   1050 <mq_close@plt>
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
mov    -0x20(%rbp),%rdi
call   10c0 <dump_mqueue_state@plt>
mov    -0x20(%rbp),%rdi
mov    0x2bce(%rip),%rax
mov    (%rax),%esi
mov    0x2bcd(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   1090 <mq_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    143c <main+0x26c>
lea    0xc15(%rip),%rdi
call   10b0 <perror@plt>
jmp    158d <main+0x3bd>
mov    -0x18(%rbp),%rdi
lea    -0x1048(%rbp),%rsi
call   10f0 <mq_getattr@plt>
cmp    $0xffffffff,%eax
jne    1466 <main+0x296>
lea    0xc65(%rip),%rdi
call   10b0 <perror@plt>
jmp    158d <main+0x3bd>
movslq -0x1044(%rbp),%rax
cmp    $0x1000,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x1040(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x1040(%rbp)
jne    14b6 <main+0x2e6>
lea    0xc22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    158d <main+0x3bd>
jmp    14bb <main+0x2eb>
mov    -0x1040(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x1040(%rbp)
cmp    $0x0,%rax
jl     1583 <main+0x3b3>
mov    -0x18(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
movslq -0x1044(%rbp),%rdx
lea    -0x1050(%rbp),%rcx
call   10a0 <mq_receive@plt>
mov    %eax,-0x104c(%rbp)
cmpl   $0xffffffff,-0x104c(%rbp)
jne    1519 <main+0x349>
lea    0xbf4(%rip),%rdi
call   10b0 <perror@plt>
jmp    158d <main+0x3bd>
xor    %eax,%eax
cmpl   $0x0,-0x104c(%rbp)
mov    %al,-0x1079(%rbp)
jl     1544 <main+0x374>
movslq -0x104c(%rbp),%rax
cmp    $0x1000,%rax
setb   %al
mov    %al,-0x1079(%rbp)
mov    -0x1079(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movslq -0x104c(%rbp),%rax
movb   $0x0,-0x1030(%rbp,%rax,1)
mov    -0x1050(%rbp),%esi
lea    -0x1030(%rbp),%rdx
lea    0xb97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14bb <main+0x2eb>
movl   $0x0,-0x1054(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
je     15a1 <main+0x3d1>
mov    -0x18(%rbp),%rdi
call   1050 <mq_close@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <mq_unlink@plt>
mov    -0x1054(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
cmp    $0x2,%edi
jl     11fc <main+0x1c>
mov    0x8(%rsi),%r14
jmp    1203 <main+0x23>
lea    0xdfd(%rip),%r14
movabs $0x10000000000a,%rax
mov    %rax,0x8(%rsp)
xorps  %xmm0,%xmm0
mov    0x2d84(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movups %xmm0,0x10(%rsp)
mov    0x2d85(%rip),%rax
or     (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10a0 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     13ea <main+0x20a>
mov    %rax,%r15
lea    0xe1d(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x1,%ecx
call   1070 <mq_send@plt>
cmp    $0xffffffff,%eax
je     13af <main+0x1cf>
lea    0xe09(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x2a,%ecx
call   1070 <mq_send@plt>
cmp    $0xffffffff,%eax
je     1432 <main+0x252>
mov    %r15,%rdi
call   1060 <mq_close@plt>
mov    %r14,%rdi
call   10d0 <dump_mqueue_state@plt>
mov    0x2d17(%rip),%rax
mov    0x2d18(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     143b <main+0x25b>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1100 <mq_getattr@plt>
cmp    $0xffffffff,%eax
je     144e <main+0x26e>
xor    %edi,%edi
cmpl   $0x1001,0xc(%rsp)
setb   %dil
call   1080 <assert@plt>
mov    0x10(%rsp),%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1080 <assert@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     13d8 <main+0x1f8>
lea    -0x1(%rax),%rcx
mov    %rcx,0x10(%rsp)
test   %rax,%rax
jle    13e6 <main+0x206>
lea    0x20(%rsp),%rbx
lea    0x4(%rsp),%r12
lea    0xd6a(%rip),%r13
xchg   %ax,%ax
movslq 0xc(%rsp),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
call   10b0 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     1457 <main+0x277>
movslq %eax,%rbp
xor    %edi,%edi
cmp    $0x1000,%eax
setb   %dil
call   1080 <assert@plt>
movb   $0x0,0x20(%rsp,%rbp,1)
mov    0x4(%rsp),%esi
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rax
lea    -0x1(%rax),%rcx
mov    %rcx,0x10(%rsp)
test   %rax,%rax
jg     1350 <main+0x170>
jmp    1468 <main+0x288>
mov    0x2bfa(%rip),%rax
mov    (%rax),%rax
mov    0x2bd8(%rip),%rcx
cmp    (%rcx),%rax
jne    1432 <main+0x252>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    1468 <main+0x288>
lea    0xcfc(%rip),%rdi
call   1030 <puts@plt>
jmp    1463 <main+0x283>
xor    %ebp,%ebp
jmp    1468 <main+0x288>
mov    0x2bbf(%rip),%rax
mov    (%rax),%rax
mov    0x2bd5(%rip),%rcx
cmp    (%rcx),%rax
je     148c <main+0x2ac>
lea    0xc3c(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
cmpb   $0x2f,(%r14)
je     1478 <main+0x298>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
lea    0xc24(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1478 <main+0x298>
lea    0xc4f(%rip),%rdi
jmp    145e <main+0x27e>
lea    0xc05(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
jmp    1470 <main+0x290>
lea    0xc4d(%rip),%rdi
jmp    145e <main+0x27e>
lea    0xc4f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
mov    %r15,%rdi
call   1060 <mq_close@plt>
mov    %r14,%rdi
call   10f0 <mq_unlink@plt>
mov    %ebp,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b2d(%rip),%rax
mov    (%rax),%edi
lea    0xb78(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i64, i64 }
@.str = [20 x i8] c"/test_message_queue\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@ENOSYS = global i64 0
@stderr = global i32 0
@.str.1 = [51 x i8] c"Exit because the kernel does not support mq_open.\0A\00"
@.str.2 = [8 x i8] c"mq_open\00"
@.str.3 = [43 x i8] c"It seems that the initial '/' is missing.\0A\00"
@.str.4 = [14 x i8] c"Hello, world!\00"
@EPERM = global i64 0
@.str.5 = [31 x i8] c"mq_send() is denied, exiting.\0A\00"
@.str.6 = [8 x i8] c"mq_send\00"
@.str.7 = [18 x i8] c"The answer is 42.\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.8 = [11 x i8] c"mq_getattr\00"
@.str.9 = [55 x i8] c"There is no message in the queue. It has disappeared!\0A\00"
@.str.10 = [11 x i8] c"mq_receive\00"
@.str.11 = [35 x i8] c"Received message with prio %u: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [4096 x i8]
%10 = alloca %struct.mq_attr
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 1, i32* %13
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %7
br label %20
20: ; preds = %16, %2
%21 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 3
store i64 0, i64* %21
%22 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 0
store i32 10, i32* %22
%23 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 1
store i32 4096, i32* %23
%24 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 2
store i64 0, i64* %24
%25 = load i8*, i8** %7
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %26, %27
%29 = load i32, i32* @O_EXCL
%30 = or i32 %28, %29
%31 = call i64 (i8*, i32, ...) @mq_open(i8* %25, i32 %30, i32 384, %struct.mq_attr* %10)
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = icmp eq i64 %32, -1
br i1 %33, label %34, label %53
34: ; preds = %20
%35 = load i64, i64* @errno
%36 = load i64, i64* @ENOSYS
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %34
%43 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 47
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %49, %42
store i32 1, i32* %3
br label %159
53: ; preds = %20
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %8
%54 = load i64, i64* %6
%55 = load i8*, i8** %8
%56 = load i8*, i8** %8
%57 = call i32 @strlen(i8* %56)
%58 = call i32 @mq_send(i64 %54, i8* %55, i32 %57, i32 1)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %68
60: ; preds = %53
%61 = load i64, i64* @errno
%62 = load i64, i64* @EPERM
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %13
br label %149
66: ; preds = %60
%67 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %149
68: ; preds = %53
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8** %8
%69 = load i64, i64* %6
%70 = load i8*, i8** %8
%71 = load i8*, i8** %8
%72 = call i32 @strlen(i8* %71)
%73 = call i32 @mq_send(i64 %69, i8* %70, i32 %72, i32 42)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %149
77: ; preds = %68
%78 = load i64, i64* %6
%79 = call i32 @mq_close(i64 %78)
store i64 -1, i64* %6
%80 = load i8*, i8** %7
%81 = call i32 @dump_mqueue_state(i8* %80)
%82 = load i8*, i8** %7
%83 = load i32, i32* @O_RDONLY
%84 = load i32, i32* @O_NONBLOCK
%85 = or i32 %83, %84
%86 = call i64 (i8*, i32, ...) @mq_open(i8* %82, i32 %85)
store i64 %86, i64* %6
%87 = load i64, i64* %6
%88 = icmp eq i64 %87, -1
br i1 %88, label %89, label %91
89: ; preds = %77
%90 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %149
91: ; preds = %77
%92 = load i64, i64* %6
%93 = call i32 @mq_getattr(i64 %92, %struct.mq_attr* %10)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %149
97: ; preds = %91
%98 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 1
%99 = load i32, i32* %98
%100 = sext i32 %99 to i64
%101 = icmp ule i64 %100, 4096
%102 = zext i1 %101 to i32
%103 = call i32 @assert(i32 %102)
%104 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 2
%105 = load i64, i64* %104
%106 = icmp sge i64 %105, 0
%107 = zext i1 %106 to i32
%108 = call i32 @assert(i32 %107)
%109 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 2
%110 = load i64, i64* %109
%111 = icmp eq i64 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %97
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.9, i64 0, i64 0))
br label %149
114: ; preds = %97
br label %115
115: ; preds = %138, %114
%116 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 2
%117 = load i64, i64* %116
%118 = add nsw i64 %117, -1
store i64 %118, i64* %116
%119 = icmp sge i64 %118, 0
br i1 %119, label %120, label %148
120: ; preds = %115
%121 = load i64, i64* %6
%122 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%123 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %10, i32 0, i32 1
%124 = load i32, i32* %123
%125 = sext i32 %124 to i64
%126 = call i32 @mq_receive(i64 %121, i8* %122, i64 %125, i32* %12)
store i32 %126, i32* %11
%127 = load i32, i32* %11
%128 = icmp eq i32 %127, -1
br i1 %128, label %129, label %131
129: ; preds = %120
%130 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %149
131: ; preds = %120
%132 = load i32, i32* %11
%133 = icmp sge i32 %132, 0
br i1 %133, label %134, label %138
134: ; preds = %131
%135 = load i32, i32* %11
%136 = sext i32 %135 to i64
%137 = icmp ult i64 %136, 4096
br label %138
138: ; preds = %134, %131
%139 = phi i1 [ false, %131 ], [ %137, %134 ]
%140 = zext i1 %139 to i32
%141 = call i32 @assert(i32 %140)
%142 = load i32, i32* %11
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %143
store i8 0, i8* %144
%145 = load i32, i32* %12
%146 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %145, i8* %146)
br label %115
148: ; preds = %115
store i32 0, i32* %13
br label %149
149: ; preds = %148, %129, %112, %95, %89, %75, %66, %64
%150 = load i64, i64* %6
%151 = icmp ne i64 %150, -1
br i1 %151, label %152, label %155
152: ; preds = %149
%153 = load i64, i64* %6
%154 = call i32 @mq_close(i64 %153)
br label %155
155: ; preds = %152, %149
%156 = load i8*, i8** %7
%157 = call i32 @mq_unlink(i8* %156)
%158 = load i32, i32* %13
store i32 %158, i32* %3
br label %159
159: ; preds = %155, %52
%160 = load i32, i32* %3
ret i32 %160
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i64, i64 }
@.str = [20 x i8] c"/test_message_queue\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@ENOSYS = global i64 0
@stderr = global i32 0
@.str.1 = [51 x i8] c"Exit because the kernel does not support mq_open.\0A\00"
@.str.2 = [8 x i8] c"mq_open\00"
@.str.3 = [43 x i8] c"It seems that the initial '/' is missing.\0A\00"
@.str.4 = [14 x i8] c"Hello, world!\00"
@EPERM = global i64 0
@.str.6 = [8 x i8] c"mq_send\00"
@.str.7 = [18 x i8] c"The answer is 42.\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.8 = [11 x i8] c"mq_getattr\00"
@.str.10 = [11 x i8] c"mq_receive\00"
@.str.11 = [35 x i8] c"Received message with prio %u: %s\0A\00"
@str = [54 x i8] c"There is no message in the queue. It has disappeared!\00"
@str.12 = [30 x i8] c"mq_send() is denied, exiting.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca %struct.mq_attr
%5 = alloca i32
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.mq_attr* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
br label %13
13: ; preds = %10, %2
%14 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %2 ]
%15 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i64 0, i32 0
store i32 10, i32* %15
%16 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i64 0, i32 1
store i32 4096, i32* %16
%17 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %4, i64 0, i32 2
%18 = bitcast i64* %17 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %18
%19 = load i32, i32* @O_WRONLY
%20 = load i32, i32* @O_CREAT
%21 = or i32 %20, %19
%22 = load i32, i32* @O_EXCL
%23 = or i32 %21, %22
%24 = call i64 (i8*, i32, ...) @mq_open(i8* %14, i32 %23, i32 384, %struct.mq_attr* %4)
%25 = icmp eq i64 %24, -1
br i1 %25, label %26, label %41
26: ; preds = %13
%27 = load i64, i64* @errno
%28 = load i64, i64* @ENOSYS
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%36 = load i8, i8* %14
%37 = icmp eq i8 %36, 47
br i1 %37, label %116, label %38
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %116
41: ; preds = %13
%42 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @mq_send(i64 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %42, i32 1)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i64, i64* @errno
%47 = load i64, i64* @EPERM
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.12, i64 0, i64 0))
br label %109
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %109
53: ; preds = %41
%54 = call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%55 = call i32 @mq_send(i64 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %54, i32 42)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %109
59: ; preds = %53
%60 = call i32 @mq_close(i64 %24)
%61 = call i32 @dump_mqueue_state(i8* %14)
%62 = load i32, i32* @O_RDONLY
%63 = load i32, i32* @O_NONBLOCK
%64 = or i32 %63, %62
%65 = call i64 (i8*, i32, ...) @mq_open(i8* %14, i32 %64)
%66 = icmp eq i64 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %59
%68 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %113
69: ; preds = %59
%70 = call i32 @mq_getattr(i64 %65, %struct.mq_attr* %4)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %109
74: ; preds = %69
%75 = load i32, i32* %16
%76 = icmp ult i32 %75, 4097
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
%79 = load i64, i64* %17
%80 = lshr i64 %79, 63
%81 = trunc i64 %80 to i32
%82 = xor i32 %81, 1
%83 = call i32 @assert(i32 %82)
%84 = load i64, i64* %17
%85 = icmp eq i64 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %74
%87 = add nsw i64 %84, -1
store i64 %87, i64* %17
%88 = icmp sgt i64 %84, 0
br i1 %88, label %91, label %109
89: ; preds = %74
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %109
91: ; preds = %86, %98
%92 = load i32, i32* %16
%93 = sext i32 %92 to i64
%94 = call i32 @mq_receive(i64 %65, i8* %6, i64 %93, i32* %5)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %98
96: ; preds = %91
%97 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %109
98: ; preds = %91
%99 = sext i32 %94 to i64
%100 = icmp ult i32 %94, 4096
%101 = zext i1 %100 to i32
%102 = call i32 @assert(i32 %101)
%103 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %99
store i8 0, i8* %103
%104 = load i32, i32* %5
%105 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %104, i8* %6)
%106 = load i64, i64* %17
%107 = add nsw i64 %106, -1
store i64 %107, i64* %17
%108 = icmp sgt i64 %106, 0
br i1 %108, label %91, label %109
109: ; preds = %98, %96, %86, %89, %72, %57, %51, %49
%110 = phi i32 [ 1, %89 ], [ 1, %72 ], [ 1, %57 ], [ 1, %51 ], [ 0, %49 ], [ 1, %96 ], [ 0, %86 ], [ 0, %98 ]
%111 = phi i64 [ %65, %89 ], [ %65, %72 ], [ %24, %57 ], [ %24, %51 ], [ %24, %49 ], [ %65, %96 ], [ %65, %86 ], [ %65, %98 ]
%112 = call i32 @mq_close(i64 %111)
br label %113
113: ; preds = %67, %109
%114 = phi i32 [ %110, %109 ], [ 1, %67 ]
%115 = call i32 @mq_unlink(i8* %14)
br label %116
116: ; preds = %34, %38, %113
%117 = phi i32 [ %114, %113 ], [ 1, %38 ], [ 1, %34 ]
ret i32 %117
}