#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;
  int /*<<< orphan*/ mq_curmsgs;
};
typedef int pid_t;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ mqd_t;
typedef int mode_t;

/* Variables and functions */
scalar_t__ ECHILD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mq_getattr(int /*<<< orphan*/, struct mq_attr *);
int /*<<< orphan*/ mq_open(char *, int, int, struct mq_attr *);
scalar_t__ mq_receive(int /*<<< orphan*/, char *, int, int /*<<< orphan*/ *);
scalar_t__ mq_send(int /*<<< orphan*/, char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
int wait(int *);
int main(int argc, char **argv) {
  int i, flags, status, msg_num = 5;
  char name[] = "/mq", msg[2048];
  mode_t perms;
  mqd_t mqd;
  struct mq_attr attr;
  pid_t pid;
  attr.mq_maxmsg = 50;
  attr.mq_msgsize = 2048;
  flags = O_RDWR | O_CREAT;
  perms = 0664;
  if ((mqd = mq_open(name, flags, perms, &attr)) < 0) {
    perror("mq_open() ");
    exit(EXIT_FAILURE);
  }
  if (mq_getattr(mqd, &attr) < 0) {
    perror("mq_getattr() ");
    exit(EXIT_FAILURE);
  }
  printf("Maximum of messages on queue: %ld\n", attr.mq_maxmsg);
  printf("Maximum message size: %ld\n", attr.mq_msgsize);
  printf("Messages currently on queue: %ld\n", attr.mq_curmsgs);
  pid = fork();
  if (pid < 0) {
    perror("fork() ");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    for (i = 0; i < msg_num; ++i) {
      memset(msg, 0, sizeof(msg));
      if (mq_receive(mqd, msg, sizeof(msg), NULL) < 0) {
        perror("mq_receive() ");
        exit(EXIT_FAILURE);
      } else {
        printf("Received [%s]\n", msg);
      }
    }
    exit(EXIT_SUCCESS);
  } else {
  }
  for (i = 0; i < msg_num; ++i) {
    memset(msg, 0, sizeof(msg));
    snprintf(msg, sizeof(msg), "message %d", i);
    if (mq_send(mqd, msg, strlen(msg), 30) < 0) {
      perror("mq_send() ");
      exit(EXIT_FAILURE);
    }
  }
  for (;;) {
    pid = wait(&status);
    if (pid == -1) {
      if (errno == ECHILD) {
        printf("No More children\n");
        exit(EXIT_SUCCESS);
      } else {
        perror("wait() ");
        exit(EXIT_FAILURE);
      }
    } else {
      printf("Wait child with pid %u and status %d\n", pid, status);
    }
  }
  mq_unlink(name);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x20(%rbp)
mov    0xe1a(%rip),%eax
mov    %eax,-0x24(%rbp)
movl   $0x32,-0x848(%rbp)
movl   $0x800,-0x844(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    0x2deb(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1b4,-0x834(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x834(%rbp),%edx
lea    -0x848(%rbp),%rcx
call   1080 <mq_open@plt>
mov    %eax,-0x838(%rbp)
cmp    $0x0,%eax
jge    125e <main+0x9e>
lea    0xdb9(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x838(%rbp),%edi
lea    -0x848(%rbp),%rsi
call   10e0 <mq_getattr@plt>
cmp    $0x0,%rax
jge    1294 <main+0xd4>
lea    0xd8e(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x848(%rbp),%esi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x844(%rbp),%esi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x840(%rbp),%esi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x84c(%rbp)
cmpl   $0x0,-0x84c(%rbp)
jge    1304 <main+0x144>
lea    0xd8c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x84c(%rbp)
jne    13ac <main+0x1ec>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    139e <main+0x1de>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    -0x838(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x800,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <mq_receive@plt>
cmp    $0x0,%rax
jge    1376 <main+0x1b6>
lea    0xd22(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x830(%rbp),%rsi
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1390 <main+0x1d0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1318 <main+0x158>
mov    0x2c13(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    13b1 <main+0x1f1>
jmp    13b6 <main+0x1f6>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    146d <main+0x2ad>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
lea    -0x830(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x800,%esi
lea    0xcb0(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x838(%rbp),%eax
mov    %eax,-0x85c(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x858(%rbp)
lea    -0x830(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x85c(%rbp),%edi
mov    -0x858(%rbp),%rsi
mov    %eax,%edx
mov    $0x1e,%ecx
call   1070 <mq_send@plt>
cmp    $0x0,%rax
jge    145a <main+0x29a>
lea    0xc66(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2b75(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    145f <main+0x29f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13bd <main+0x1fd>
jmp    1472 <main+0x2b2>
lea    -0x1c(%rbp),%rdi
call   10c0 <wait@plt>
mov    %eax,-0x84c(%rbp)
cmpl   $0xffffffff,-0x84c(%rbp)
jne    14de <main+0x31e>
mov    0x2b3b(%rip),%rax
mov    (%rax),%rax
mov    0x2b21(%rip),%rcx
cmp    (%rcx),%rax
jne    14c4 <main+0x304>
lea    0xc09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2afb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xbff(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2af1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x84c(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1472 <main+0x2b2>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x820,%rsp
movl   $0x716d2f,0x1c(%rsp)
movabs $0x80000000032,%rax
mov    %rax,0x10(%rsp)
mov    0x2de7(%rip),%rax
mov    0x2df8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x1c(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    $0x1b4,%edx
call   1090 <mq_open@plt>
test   %eax,%eax
jns    1228 <main+0x58>
lea    0xddd(%rip),%rdi
jmp    1543 <main+0x373>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   10f0 <mq_getattr@plt>
test   %rax,%rax
jns    1247 <main+0x77>
lea    0xdc9(%rip),%rdi
jmp    1543 <main+0x373>
mov    0x10(%rsp),%esi
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%esi
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
jns    1294 <main+0xc4>
lea    0xdea(%rip),%rdi
jmp    1543 <main+0x373>
mov    %eax,%ebp
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
test   %ebp,%ebp
jne    13cb <main+0x1fb>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x800,%edx
xor    %ecx,%ecx
call   10a0 <mq_receive@plt>
test   %rax,%rax
js     13bf <main+0x1ef>
lea    0xdbd(%rip),%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   10a0 <mq_receive@plt>
test   %rax,%rax
js     13bf <main+0x1ef>
lea    0xd7e(%rip),%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   10a0 <mq_receive@plt>
test   %rax,%rax
js     13bf <main+0x1ef>
lea    0xd43(%rip),%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   10a0 <mq_receive@plt>
test   %rax,%rax
js     13bf <main+0x1ef>
lea    0xd08(%rip),%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   10a0 <mq_receive@plt>
test   %rax,%rax
jns    1556 <main+0x386>
lea    0xcbb(%rip),%rdi
jmp    1543 <main+0x373>
lea    0xccc(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x800,%esi
xor    %ecx,%ecx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
mov    $0x1e,%ecx
call   1080 <mq_send@plt>
test   %rax,%rax
js     153c <main+0x36c>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
lea    0xc7b(%rip),%rdx
mov    %rbp,%rdi
mov    $0x800,%esi
mov    $0x1,%ecx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
mov    $0x1e,%ecx
call   1080 <mq_send@plt>
test   %rax,%rax
js     153c <main+0x36c>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
lea    0xc2c(%rip),%rdx
mov    %rbp,%rdi
mov    $0x800,%esi
mov    $0x2,%ecx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
mov    $0x1e,%ecx
call   1080 <mq_send@plt>
test   %rax,%rax
js     153c <main+0x36c>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
lea    0xbdd(%rip),%rdx
mov    %rbp,%rdi
mov    $0x800,%esi
mov    $0x3,%ecx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
mov    $0x1e,%ecx
call   1080 <mq_send@plt>
test   %rax,%rax
js     153c <main+0x36c>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
lea    0xb92(%rip),%rdx
mov    %rbp,%rdi
mov    $0x800,%esi
mov    $0x4,%ecx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
mov    $0x1e,%ecx
call   1080 <mq_send@plt>
test   %rax,%rax
jns    156b <main+0x39b>
lea    0xb66(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2a79(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xb32(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    15cf <main+0x3ff>
lea    0xc(%rsp),%rdi
call   10d0 <wait@plt>
cmp    $0xffffffff,%eax
je     15ad <main+0x3dd>
lea    0xb3b(%rip),%r14
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10d0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1590 <main+0x3c0>
mov    0x2a1c(%rip),%rax
mov    (%rax),%rax
mov    0x2a02(%rip),%rcx
cmp    (%rcx),%rax
jne    15dd <main+0x40d>
lea    0xb18(%rip),%rdi
call   1030 <puts@plt>
mov    0x29e2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xad0(%rip),%rdi
jmp    1543 <main+0x373>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32 }
@__const.main.name = [4 x i8] c"/mq\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [11 x i8] c"mq_open() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"mq_getattr() \00"
@.str.2 = [35 x i8] c"Maximum of messages on queue: %ld\0A\00"
@.str.3 = [27 x i8] c"Maximum message size: %ld\0A\00"
@.str.4 = [34 x i8] c"Messages currently on queue: %ld\0A\00"
@.str.5 = [8 x i8] c"fork() \00"
@.str.6 = [14 x i8] c"mq_receive() \00"
@.str.7 = [15 x i8] c"Received [%s]\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [11 x i8] c"message %d\00"
@.str.9 = [11 x i8] c"mq_send() \00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.10 = [18 x i8] c"No More children\0A\00"
@.str.11 = [8 x i8] c"wait() \00"
@.str.12 = [38 x i8] c"Wait child with pid %u and status %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 i32
%9 = alloca i32
%10 = alloca [4 x i8]
%11 = alloca [2048 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.mq_attr
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5, i32* %9
%16 = bitcast [4 x i8]* %10 to i8*
%17 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %14, i32 0, i32 0
store i32 50, i32* %17
%18 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %14, i32 0, i32 1
store i32 2048, i32* %18
%19 = load i32, i32* @O_RDWR
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
store i32 %21, i32* %7
store i32 436, i32* %12
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%23 = load i32, i32* %7
%24 = load i32, i32* %12
%25 = call i32 @mq_open(i8* %22, i32 %23, i32 %24, %struct.mq_attr* %14)
store i32 %25, i32* %13
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %2
%32 = load i32, i32* %13
%33 = call i64 @mq_getattr(i32 %32, %struct.mq_attr* %14)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %31
%40 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %14, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %14, i32 0, i32 1
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %14, i32 0, i32 2
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = call i32 (...) @fork()
store i32 %49, i32* %15
%50 = load i32, i32* %15
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %39
%53 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %39
%57 = load i32, i32* %15
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %85
59: ; preds = %56
store i32 0, i32* %6
br label %60
60: ; preds = %79, %59
%61 = load i32, i32* %6
%62 = load i32, i32* %9
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %82
64: ; preds = %60
%65 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%66 = call i32 @memset(i8* %65, i32 0, i32 2048)
%67 = load i32, i32* %13
%68 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%69 = call i64 @mq_receive(i32 %67, i8* %68, i32 2048, i32* null)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %64
%76 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %75
br label %79
79: ; preds = %78
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
store i32 %81, i32* %6
br label %60
82: ; preds = %60
%83 = load i32, i32* @EXIT_SUCCESS
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %56
br label %86
86: ; preds = %85
br label %87
87: ; preds = %86
store i32 0, i32* %6
br label %88
88: ; preds = %109, %87
%89 = load i32, i32* %6
%90 = load i32, i32* %9
%91 = icmp slt i32 %89, %90
br i1 %91, label %92, label %112
92: ; preds = %88
%93 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%94 = call i32 @memset(i8* %93, i32 0, i32 2048)
%95 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%96 = load i32, i32* %6
%97 = call i32 @snprintf(i8* %95, i32 2048, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 %96)
%98 = load i32, i32* %13
%99 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%100 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%101 = call i32 @strlen(i8* %100)
%102 = call i64 @mq_send(i32 %98, i8* %99, i32 %101, i32 30)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %92
%105 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%106 = load i32, i32* @EXIT_FAILURE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %92
br label %109
109: ; preds = %108
%110 = load i32, i32* %6
%111 = add nsw i32 %110, 1
store i32 %111, i32* %6
br label %88
112: ; preds = %88
br label %113
113: ; preds = %133, %112
%114 = call i32 @wait(i32* %8)
store i32 %114, i32* %15
%115 = load i32, i32* %15
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %129
117: ; preds = %113
%118 = load i64, i64* @errno
%119 = load i64, i64* @ECHILD
%120 = icmp eq i64 %118, %119
br i1 %120, label %121, label %125
121: ; preds = %117
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0))
%123 = load i32, i32* @EXIT_SUCCESS
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %117
%126 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%127 = load i32, i32* @EXIT_FAILURE
%128 = call i32 @exit(i32 %127)
unreachable
129: ; preds = %113
%130 = load i32, i32* %15
%131 = load i32, i32* %8
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i32 %130, i32 %131)
br label %133
133: ; preds = %129
br label %113
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [11 x i8] c"mq_open() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"mq_getattr() \00"
@.str.2 = [35 x i8] c"Maximum of messages on queue: %ld\0A\00"
@.str.3 = [27 x i8] c"Maximum message size: %ld\0A\00"
@.str.4 = [34 x i8] c"Messages currently on queue: %ld\0A\00"
@.str.5 = [8 x i8] c"fork() \00"
@.str.6 = [14 x i8] c"mq_receive() \00"
@.str.7 = [15 x i8] c"Received [%s]\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [11 x i8] c"message %d\00"
@.str.9 = [11 x i8] c"mq_send() \00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.11 = [8 x i8] c"wait() \00"
@.str.12 = [38 x i8] c"Wait child with pid %u and status %d\0A\00"
@str = [17 x i8] c"No More children\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = alloca %struct.mq_attr
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 7433519, i32* %4
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = bitcast %struct.mq_attr* %6 to i8*
%11 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i64 0, i32 0
store i32 50, i32* %11
%12 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i64 0, i32 1
store i32 2048, i32* %12
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %14, %13
%16 = call i32 @mq_open(i8* %8, i32 %15, i32 436, %struct.mq_attr* %6)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = call i64 @mq_getattr(i32 %16, %struct.mq_attr* %6)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %22
%30 = load i32, i32* %11
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %12
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %6, i64 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = call i32 (...) @fork()
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %29
%40 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %29
%44 = icmp eq i32 %37, 0
%45 = call i32 @memset(i8* %9, i32 0, i32 2048)
br i1 %44, label %51, label %46
46: ; preds = %43
%47 = call i32 @snprintf(i8* %9, i32 2048, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 0)
%48 = call i32 @strlen(i8* %9)
%49 = call i64 @mq_send(i32 %16, i8* %9, i32 %48, i32 30)
%50 = icmp slt i64 %49, 0
br i1 %50, label %109, label %82
51: ; preds = %43
%52 = call i64 @mq_receive(i32 %16, i8* %9, i32 2048, i32* null)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %73, %68, %63, %58, %51
%55 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %51
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%60 = call i32 @memset(i8* %9, i32 0, i32 2048)
%61 = call i64 @mq_receive(i32 %16, i8* %9, i32 2048, i32* null)
%62 = icmp slt i64 %61, 0
br i1 %62, label %54, label %63
63: ; preds = %58
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%65 = call i32 @memset(i8* %9, i32 0, i32 2048)
%66 = call i64 @mq_receive(i32 %16, i8* %9, i32 2048, i32* null)
%67 = icmp slt i64 %66, 0
br i1 %67, label %54, label %68
68: ; preds = %63
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%70 = call i32 @memset(i8* %9, i32 0, i32 2048)
%71 = call i64 @mq_receive(i32 %16, i8* %9, i32 2048, i32* null)
%72 = icmp slt i64 %71, 0
br i1 %72, label %54, label %73
73: ; preds = %68
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%75 = call i32 @memset(i8* %9, i32 0, i32 2048)
%76 = call i64 @mq_receive(i32 %16, i8* %9, i32 2048, i32* null)
%77 = icmp slt i64 %76, 0
br i1 %77, label %54, label %78
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%80 = load i32, i32* @EXIT_SUCCESS
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %46
%83 = call i32 @memset(i8* %9, i32 0, i32 2048)
%84 = call i32 @snprintf(i8* %9, i32 2048, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 1)
%85 = call i32 @strlen(i8* %9)
%86 = call i64 @mq_send(i32 %16, i8* %9, i32 %85, i32 30)
%87 = icmp slt i64 %86, 0
br i1 %87, label %109, label %88
88: ; preds = %82
%89 = call i32 @memset(i8* %9, i32 0, i32 2048)
%90 = call i32 @snprintf(i8* %9, i32 2048, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 2)
%91 = call i32 @strlen(i8* %9)
%92 = call i64 @mq_send(i32 %16, i8* %9, i32 %91, i32 30)
%93 = icmp slt i64 %92, 0
br i1 %93, label %109, label %94
94: ; preds = %88
%95 = call i32 @memset(i8* %9, i32 0, i32 2048)
%96 = call i32 @snprintf(i8* %9, i32 2048, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 3)
%97 = call i32 @strlen(i8* %9)
%98 = call i64 @mq_send(i32 %16, i8* %9, i32 %97, i32 30)
%99 = icmp slt i64 %98, 0
br i1 %99, label %109, label %100
100: ; preds = %94
%101 = call i32 @memset(i8* %9, i32 0, i32 2048)
%102 = call i32 @snprintf(i8* %9, i32 2048, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 4)
%103 = call i32 @strlen(i8* %9)
%104 = call i64 @mq_send(i32 %16, i8* %9, i32 %103, i32 30)
%105 = icmp slt i64 %104, 0
br i1 %105, label %109, label %106
106: ; preds = %100
%107 = call i32 @wait(i32* %3)
%108 = icmp eq i32 %107, -1
br i1 %108, label %113, label %125
109: ; preds = %100, %94, %88, %82, %46
%110 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%111 = load i32, i32* @EXIT_FAILURE
%112 = call i32 @exit(i32 %111)
unreachable
113: ; preds = %125, %106
%114 = load i64, i64* @errno
%115 = load i64, i64* @ECHILD
%116 = icmp eq i64 %114, %115
br i1 %116, label %117, label %121
117: ; preds = %113
%118 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%119 = load i32, i32* @EXIT_SUCCESS
%120 = call i32 @exit(i32 %119)
unreachable
121: ; preds = %113
%122 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%123 = load i32, i32* @EXIT_FAILURE
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %106, %125
%126 = phi i32 [ %129, %125 ], [ %107, %106 ]
%127 = load i32, i32* %3
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i32 %126, i32 %127)
%129 = call i32 @wait(i32* %3)
%130 = icmp eq i32 %129, -1
br i1 %130, label %113, label %125
}