#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int mqd_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int mq_open(char const *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ msg_rcv(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
void child(const char *mqname) {
  mqd_t mqdes = mq_open(mqname, O_RDWR | O_CREAT, 0666, 0);
  if (mqdes == -1) {
    perror("mq_open() failed");
    exit(1);
  }
  int i = 1;
  while (1) {
    msg_rcv(mqdes, i);
    printf("Client: %d\n", i);
    fflush(stdout);
    i++;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e78(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1050 <mq_open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b1 <child+0x51>
lea    0xe5e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <msg_rcv@plt>
mov    -0x10(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x10(%rbp)
jmp    11b8 <child+0x58>

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e72(%rip),%rax
mov    0x2e83(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1050 <mq_open@plt>
cmp    $0xffffffff,%eax
je     11c0 <child+0x60>
mov    %eax,%ebx
mov    $0x1,%ebp
lea    0xe79(%rip),%r14
mov    0x2e31(%rip),%r15
nop
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <msg_rcv@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
add    $0x1,%ebp
jmp    11a0 <child+0x40>
lea    0xe39(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [17 x i8] c"mq_open() failed\00"
@.str.1 = [12 x i8] c"Client: %d\0A\00"
@stdout = global i32 0
define void @child(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = call i32 @mq_open(i8* %5, i32 %8, i32 438, i32 0)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
store i32 1, i32* %4
br label %16
16: ; preds = %15, %16
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 @msg_rcv(i32 %17, i32 %18)
%20 = load i32, i32* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %16
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [17 x i8] c"mq_open() failed\00"
@.str.1 = [12 x i8] c"Client: %d\0A\00"
@stdout = global i32 0
define void @child(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @mq_open(i8* %0, i32 %4, i32 438, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1, %10
%11 = phi i32 [ %16, %10 ], [ 1, %1 ]
%12 = tail call i32 @msg_rcv(i32 %5, i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%14 = load i32, i32* @stdout
%15 = tail call i32 @fflush(i32 %14)
%16 = add nuw nsw i32 %11, 1
br label %10
}