#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_flags;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ mqstat;
typedef int /*<<< orphan*/ mqd_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ memset(struct mq_attr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mq_close(int /*<<< orphan*/);
int /*<<< orphan*/ mq_getattr(int /*<<< orphan*/, struct mq_attr *);
int /*<<< orphan*/ mq_open(char *, int, int, struct mq_attr *);
int mq_receive(int /*<<< orphan*/, char *, int, int /*<<< orphan*/ *);
int mq_send(int /*<<< orphan*/, char const *, int, int);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(void) {
  struct mq_attr mqstat, attr;
  char r_msg_ptr[3][128];
  const char *s_msg_ptr[] = {"msg test 1", "msg test 2", "msg test 3"};
  int i;
  int oflag = O_CREAT | O_RDWR;
  int ret_code = 0;
  mqd_t mq = 0;
  pid_t pid;
  memset(&mqstat, 0, sizeof(mqstat));
  mqstat.mq_maxmsg = 3;
  mqstat.mq_msgsize = 128;
  mqstat.mq_flags = 0;
  if (((mqd_t)-1) == (mq = mq_open("/testmsg", oflag, 0777, &mqstat))) {
    perror("mq_open doesn't return success \n");
    return 2;
  }
  switch ((pid = fork())) {
  case -1:
    perror("fork");
    ret_code = 2;
    break;
  case 0:
    mq_getattr(mq, &attr);
    for (i = 0; i < 3 && ret_code == 0; i++) {
      printf("[%d] s_msg_ptr is '%s' \n", i + 1, s_msg_ptr[i]);
      printf("Prepare to send message...\n");
      if (-1 == mq_send(mq, s_msg_ptr[i], attr.mq_msgsize, 1)) {
        perror("mq_send doesn't return success \n");
        ret_code = 2;
      } else {
        printf("Process %ld send message '%s' to "
               "process %ld \n",
               (long)getpid(), s_msg_ptr[i], (long)pid);
      }
    }
    (void)wait(NULL);
    break;
  default:
    printf("Enter into child process...\n");
    mq_getattr(mq, &attr);
    for (i = 0; i < 3 && ret_code == 0; i++) {
      printf("Prepare to receive [%d] messages...\n", i + 1);
      if (-1 == mq_receive(mq, r_msg_ptr[i], attr.mq_msgsize, NULL)) {
        perror("mq_receive doesn't return success \n");
        ret_code = 2;
      } else {
        printf("process %ld receive message '%s' from "
               "process %ld \n",
               (long)getpid(), r_msg_ptr[i], (long)getppid());
      }
    }
    exit(ret_code);
    break;
  }
  (void)mq_close(mq);
  (void)mq_unlink("/testmsg");
  return ret_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2bf7(%rip),%rax
mov    %rax,-0x1d0(%rbp)
mov    0x2bf1(%rip),%rax
mov    %rax,-0x1c8(%rbp)
mov    0x2beb(%rip),%rax
mov    %rax,-0x1c0(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    0x2dac(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1d8(%rbp)
movl   $0x0,-0x1dc(%rbp)
movl   $0x0,-0x1e0(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x3,-0x18(%rbp)
movl   $0x80,-0x14(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x1d8(%rbp),%esi
lea    0xda6(%rip),%rdi
mov    $0x1ff,%edx
lea    -0x18(%rbp),%rcx
call   1080 <mq_open@plt>
mov    %eax,%ecx
mov    %ecx,-0x1e0(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12b6 <main+0xd6>
lea    0xd85(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    158e <main+0x3ae>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %rax,-0x1e8(%rbp)
mov    %rax,%rcx
mov    %rcx,-0x1f0(%rbp)
sub    $0xffffffffffffffff,%rax
je     12f2 <main+0x112>
jmp    12dd <main+0xfd>
mov    -0x1f0(%rbp),%rax
test   %rax,%rax
je     130d <main+0x12d>
jmp    1433 <main+0x253>
lea    0xd52(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x1dc(%rbp)
jmp    156e <main+0x38e>
mov    -0x1e0(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1100 <mq_getattr@plt>
movl   $0x0,-0x1d4(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x1d4(%rbp)
mov    %al,-0x1f1(%rbp)
jge    134b <main+0x16b>
cmpl   $0x0,-0x1dc(%rbp)
sete   %al
mov    %al,-0x1f1(%rbp)
mov    -0x1f1(%rbp),%al
test   $0x1,%al
jne    135e <main+0x17e>
jmp    1425 <main+0x245>
mov    -0x1d4(%rbp),%esi
add    $0x1,%esi
movslq -0x1d4(%rbp),%rax
mov    -0x1d0(%rbp,%rax,8),%rdx
ff
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1e0(%rbp),%edi
movslq -0x1d4(%rbp),%rax
mov    -0x1d0(%rbp,%rax,8),%rsi
ff
mov    -0x24(%rbp),%edx
mov    $0x1,%ecx
call   1070 <mq_send@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13de <main+0x1fe>
lea    0xcbb(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x1dc(%rbp)
jmp    140c <main+0x22c>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
movslq -0x1d4(%rbp),%rax
mov    -0x1d0(%rbp,%rax,8),%rdx
ff
mov    -0x1e8(%rbp),%rcx
lea    0xca1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1411 <main+0x231>
mov    -0x1d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4(%rbp)
jmp    1326 <main+0x146>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
jmp    156e <main+0x38e>
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1e0(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1100 <mq_getattr@plt>
movl   $0x0,-0x1d4(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x1d4(%rbp)
mov    %al,-0x1f2(%rbp)
jge    147f <main+0x29f>
cmpl   $0x0,-0x1dc(%rbp)
sete   %al
mov    %al,-0x1f2(%rbp)
mov    -0x1f2(%rbp),%al
test   $0x1,%al
jne    1492 <main+0x2b2>
jmp    1563 <main+0x383>
mov    -0x1d4(%rbp),%esi
add    $0x1,%esi
lea    0xc50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1e0(%rbp),%edi
movslq -0x1d4(%rbp),%rax
lea    -0x1b0(%rbp),%rsi
shl    $0x7,%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <mq_receive@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    14fa <main+0x31a>
lea    0xc31(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x1dc(%rbp)
jmp    154a <main+0x36a>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x208(%rbp)
movslq -0x1d4(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
shl    $0x7,%rcx
add    %rcx,%rax
mov    %rax,-0x200(%rbp)
mov    $0x0,%al
call   10b0 <getppid@plt>
mov    -0x208(%rbp),%rsi
mov    -0x200(%rbp),%rdx
mov    %rax,%rcx
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    154f <main+0x36f>
mov    -0x1d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1d4(%rbp)
jmp    145a <main+0x27a>
mov    -0x1dc(%rbp),%edi
call   10c0 <exit@plt>
mov    -0x1e0(%rbp),%edi
call   1060 <mq_close@plt>
lea    0xaa1(%rip),%rdi
call   10d0 <mq_unlink@plt>
mov    -0x1dc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
mov    0x2de8(%rip),%rax
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movabs $0x8000000003,%rax
mov    %rax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
lea    0xddb(%rip),%rdi
mov    %ebx,%esi
mov    $0x1ff,%edx
mov    %rbp,%rcx
call   1090 <mq_open@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1349 <main+0x159>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
jne    135c <main+0x16c>
lea    0x10(%rsp),%rsi
mov    0xc(%rsp),%edi
call   1110 <mq_getattr@plt>
lea    0x2b69(%rip),%r14
lea    0xdfc(%rip),%r13
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rbx
lea    0x1(%r12),%esi
lea    0xda1(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%edx
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1080 <mq_send@plt>
cmp    $0xffffffff,%eax
je     1375 <main+0x185>
mov    %eax,%r15d
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r13,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%r15d
je     1319 <main+0x129>
add    $0x8,%r14
lea    0x1(%r12),%rax
cmp    $0x2,%r12
mov    %rax,%r12
jb     12a0 <main+0xb0>
xor    %edi,%edi
call   10f0 <wait@plt>
mov    0xc(%rsp),%edi
call   1070 <mq_close@plt>
lea    0xcf1(%rip),%rdi
call   10e0 <mq_unlink@plt>
mov    %ebp,%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcda(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%ebp
jmp    1335 <main+0x145>
cmp    $0xffffffffffffffff,%rax
jne    1388 <main+0x198>
lea    0xce2(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%ebp
jmp    1320 <main+0x130>
lea    0xced(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%ebp
jmp    1319 <main+0x129>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    0xc(%rsp),%edi
call   1110 <mq_getattr@plt>
lea    0x30(%rsp),%r14
lea    0xd54(%rip),%r13
xor    %r12d,%r12d
xor    %r15d,%r15d
lea    0x1(%r12),%esi
lea    0xcf9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%edx
mov    0xc(%rsp),%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   10a0 <mq_receive@plt>
cmp    $0xffffffff,%eax
je     1423 <main+0x233>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <getppid@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%ebp
je     141b <main+0x22b>
sub    $0xffffffffffffff80,%r14
lea    0x1(%r12),%rax
cmp    $0x2,%r12
mov    %rax,%r12
jb     13b4 <main+0x1c4>
mov    %r15d,%edi
call   10d0 <exit@plt>
lea    0xcb4(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i64 }
@.str = [11 x i8] c"msg test 1\00"
@.str.1 = [11 x i8] c"msg test 2\00"
@.str.2 = [11 x i8] c"msg test 3\00"
@__const.main.s_msg_ptr = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0)]
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.3 = [9 x i8] c"/testmsg\00"
@.str.4 = [33 x i8] c"mq_open doesn't return success \0A\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [25 x i8] c"[%d] s_msg_ptr is '%s' \0A\00"
@.str.7 = [28 x i8] c"Prepare to send message...\0A\00"
@.str.8 = [33 x i8] c"mq_send doesn't return success \0A\00"
@.str.9 = [47 x i8] c"Process %ld send message '%s' to process %ld \0A\00"
@.str.10 = [29 x i8] c"Enter into child process...\0A\00"
@.str.11 = [37 x i8] c"Prepare to receive [%d] messages...\0A\00"
@.str.12 = [36 x i8] c"mq_receive doesn't return success \0A\00"
@.str.13 = [52 x i8] c"process %ld receive message '%s' from process %ld \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.mq_attr
%3 = alloca %struct.mq_attr
%4 = alloca [3 x [128 x i8]]
%5 = alloca [3 x i8*]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %1
%11 = bitcast [3 x i8*]* %5 to i8*
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_RDWR
%14 = or i32 %12, %13
store i32 %14, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%15 = call i32 @memset(%struct.mq_attr* %2, i32 0, i32 16)
%16 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i32 0, i32 0
store i32 3, i32* %16
%17 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i32 0, i32 1
store i32 128, i32* %17
%18 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i32 0, i32 2
store i64 0, i64* %18
%19 = load i32, i32* %7
%20 = call i32 @mq_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 511, %struct.mq_attr* %2)
store i32 %20, i32* %9
%21 = icmp eq i32 -1, %20
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %1
br label %120
24: ; preds = %0
%25 = call i64 (...) @fork()
store i64 %25, i64* %10
switch i64 %25, label %73 [
i64 -1, label %26
i64 0, label %28
]
26: ; preds = %24
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %8
br label %115
28: ; preds = %24
%29 = load i32, i32* %9
%30 = call i32 @mq_getattr(i32 %29, %struct.mq_attr* %3)
store i32 0, i32* %6
br label %31
31: ; preds = %68, %28
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 3
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 0
br label %37
37: ; preds = %34, %31
%38 = phi i1 [ false, %31 ], [ %36, %34 ]
br i1 %38, label %39, label %71
39: ; preds = %37
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %41, i8* %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%48 = load i32, i32* %9
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 %50
%52 = load i8*, i8** %51
%53 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 1
%54 = load i32, i32* %53
%55 = call i32 @mq_send(i32 %48, i8* %52, i32 %54, i32 1)
%56 = icmp eq i32 -1, %55
br i1 %56, label %57, label %59
57: ; preds = %39
%58 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
store i32 2, i32* %8
br label %67
59: ; preds = %39
%60 = call i64 (...) @getpid()
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 %62
%64 = load i8*, i8** %63
%65 = load i64, i64* %10
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0), i64 %60, i8* %64, i64 %65)
br label %67
67: ; preds = %59, %57
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %31
71: ; preds = %37
%72 = call i32 @wait(i32* null)
br label %115
73: ; preds = %24
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%75 = load i32, i32* %9
%76 = call i32 @mq_getattr(i32 %75, %struct.mq_attr* %3)
store i32 0, i32* %6
br label %77
77: ; preds = %109, %73
%78 = load i32, i32* %6
%79 = icmp slt i32 %78, 3
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32, i32* %8
%82 = icmp eq i32 %81, 0
br label %83
83: ; preds = %80, %77
%84 = phi i1 [ false, %77 ], [ %82, %80 ]
br i1 %84, label %85, label %112
85: ; preds = %83
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %9
%90 = load i32, i32* %6
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [3 x [128 x i8]], [3 x [128 x i8]]* %4, i64 0, i64 %91
%93 = getelementptr inbounds [128 x i8], [128 x i8]* %92, i64 0, i64 0
%94 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 1
%95 = load i32, i32* %94
%96 = call i32 @mq_receive(i32 %89, i8* %93, i32 %95, i32* null)
%97 = icmp eq i32 -1, %96
br i1 %97, label %98, label %100
98: ; preds = %85
%99 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
store i32 2, i32* %8
br label %108
100: ; preds = %85
%101 = call i64 (...) @getpid()
%102 = load i32, i32* %6
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [3 x [128 x i8]], [3 x [128 x i8]]* %4, i64 0, i64 %103
%105 = getelementptr inbounds [128 x i8], [128 x i8]* %104, i64 0, i64 0
%106 = call i64 (...) @getppid()
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.13, i64 0, i64 0), i64 %101, i8* %105, i64 %106)
br label %108
108: ; preds = %100, %98
br label %109
109: ; preds = %108
%110 = load i32, i32* %6
%111 = add nsw i32 %110, 1
store i32 %111, i32* %6
br label %77
112: ; preds = %83
%113 = load i32, i32* %8
%114 = call i32 @exit(i32 %113)
unreachable
115: ; preds = %71, %26
%116 = load i32, i32* %9
%117 = call i32 @mq_close(i32 %116)
%118 = call i32 @mq_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%119 = load i32, i32* %8
store i32 %119, i32* %1
br label %120
120: ; preds = %115, %22
%121 = load i32, i32* %1
ret i32 %121
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i64 }
@.str = [11 x i8] c"msg test 1\00"
@.str.1 = [11 x i8] c"msg test 2\00"
@.str.2 = [11 x i8] c"msg test 3\00"
@__const.main.s_msg_ptr = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0)]
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.3 = [9 x i8] c"/testmsg\00"
@.str.4 = [33 x i8] c"mq_open doesn't return success \0A\00"
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [25 x i8] c"[%d] s_msg_ptr is '%s' \0A\00"
@.str.8 = [33 x i8] c"mq_send doesn't return success \0A\00"
@.str.9 = [47 x i8] c"Process %ld send message '%s' to process %ld \0A\00"
@.str.11 = [37 x i8] c"Prepare to receive [%d] messages...\0A\00"
@.str.12 = [36 x i8] c"mq_receive doesn't return success \0A\00"
@.str.13 = [52 x i8] c"process %ld receive message '%s' from process %ld \0A\00"
@str = [27 x i8] c"Prepare to send message...\00"
@str.14 = [28 x i8] c"Enter into child process...\00"
define i32 @main() {
%1 = alloca %struct.mq_attr
%2 = alloca %struct.mq_attr
%3 = alloca [3 x [128 x i8]]
%4 = bitcast %struct.mq_attr* %1 to i8*
%5 = bitcast %struct.mq_attr* %2 to i8*
%6 = getelementptr inbounds [3 x [128 x i8]], [3 x [128 x i8]]* %3, i64 0, i64 0, i64 0
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_RDWR
%9 = or i32 %8, %7
%10 = call i32 @memset(%struct.mq_attr* %1, i32 0, i32 16)
%11 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 0
store i32 3, i32* %11
%12 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 1
store i32 128, i32* %12
%13 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 2
store i64 0, i64* %13
%14 = call i32 @mq_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %9, i32 511, %struct.mq_attr* %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %74
18: ; preds = %0
%19 = call i64 (...) @fork()
switch i64 %19, label %46 [
i64 -1, label %20
i64 0, label %22
]
20: ; preds = %18
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %70
22: ; preds = %18
%23 = call i32 @mq_getattr(i32 %14, %struct.mq_attr* %2)
%24 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 1
br label %25
25: ; preds = %22, %38
%26 = phi i64 [ 0, %22 ], [ %27, %38 ]
%27 = add nuw nsw i64 %26, 1
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.main.s_msg_ptr, i64 0, i64 %26
%29 = load i8*, i8** %28
%30 = trunc i64 %27 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %30, i8* %29)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%33 = load i32, i32* %24
%34 = call i32 @mq_send(i32 %14, i8* %29, i32 %33, i32 1)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0))
br label %43
38: ; preds = %25
%39 = call i64 (...) @getpid()
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0), i64 %39, i8* %29, i64 0)
%41 = icmp ugt i64 %26, 1
%42 = or i1 %35, %41
br i1 %42, label %43, label %25
43: ; preds = %38, %36
%44 = phi i32 [ 2, %36 ], [ 0, %38 ]
%45 = call i32 @wait(i32* null)
br label %70
46: ; preds = %18
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.14, i64 0, i64 0))
%48 = call i32 @mq_getattr(i32 %14, %struct.mq_attr* %2)
%49 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %2, i64 0, i32 1
br label %50
50: ; preds = %46, %61
%51 = phi i64 [ 0, %46 ], [ %52, %61 ]
%52 = add nuw nsw i64 %51, 1
%53 = trunc i64 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [3 x [128 x i8]], [3 x [128 x i8]]* %3, i64 0, i64 %51, i64 0
%56 = load i32, i32* %49
%57 = call i32 @mq_receive(i32 %14, i8* %55, i32 %56, i32* null)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %50
%60 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
br label %67
61: ; preds = %50
%62 = call i64 (...) @getpid()
%63 = call i64 (...) @getppid()
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.13, i64 0, i64 0), i64 %62, i8* %55, i64 %63)
%65 = icmp ugt i64 %51, 1
%66 = or i1 %58, %65
br i1 %66, label %67, label %50
67: ; preds = %61, %59
%68 = phi i32 [ 2, %59 ], [ 0, %61 ]
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %43, %20
%71 = phi i32 [ %44, %43 ], [ 2, %20 ]
%72 = call i32 @mq_close(i32 %14)
%73 = call i32 @mq_unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %74
74: ; preds = %70, %16
%75 = phi i32 [ 2, %16 ], [ %71, %70 ]
ret i32 %75
}