#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*/ msg_snd(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stdout;
void child(const char *mqname, const char *mqname2) {
  mqd_t mqdes = mq_open(mqname, O_RDWR | O_CREAT, 0666, 0);
  if (mqdes == -1) {
    perror("mq_open");
    exit(1);
  }
  mqd_t mqdes2 = mq_open(mqname2, O_RDWR | O_CREAT, 0666, 0);
  if (mqdes == -1) {
    perror("mq_open");
    exit(1);
  }
  int i = 1;
  while (1) {
    msg_rcv(mqdes, i);
    printf("Client: received %d, sending %d\n", i, i + 1);
    fflush(stdout);
    msg_snd(mqdes2, i + 1);
    i += 2;
  }
  exit(0);
}


x86 assembly (clang, -O0):
<child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c5 <child+0x55>
lea    0xe4a(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    0x2e1f(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120a <child+0x9a>
lea    0xe05(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <msg_rcv@plt>
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
lea    0xdd9(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
call   1040 <msg_snd@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    %eax,-0x1c(%rbp)
jmp    1211 <child+0xa1>

x86 assembly (clang, -O2):
<child>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e5b(%rip),%r15
mov    0x2e6c(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
cmp    $0xffffffff,%eax
je     1211 <child+0xa1>
mov    %eax,%r14d
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
mov    %eax,%r12d
mov    $0x1,%ebx
lea    0xe3e(%rip),%r15
mov    0x2dff(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <msg_rcv@plt>
lea    0x1(%rbx),%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
mov    %r12d,%edi
mov    %ebp,%esi
call   1040 <msg_snd@plt>
add    $0x2,%ebx
jmp    11e0 <child+0x70>
lea    0xde8(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [8 x i8] c"mq_open\00"
@.str.1 = [33 x i8] c"Client: received %d, sending %d\0A\00"
@stdout = global i32 0
define void @child(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = call i32 @mq_open(i8* %8, i32 %11, i32 438, i32 0)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i32, i32* @O_RDWR
%21 = load i32, i32* @O_CREAT
%22 = or i32 %20, %21
%23 = call i32 @mq_open(i8* %19, i32 %22, i32 438, i32 0)
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
store i32 1, i32* %7
br label %30
30: ; preds = %29, %30
%31 = load i32, i32* %5
%32 = load i32, i32* %7
%33 = call i32 @msg_rcv(i32 %31, i32 %32)
%34 = load i32, i32* %7
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fflush(i32 %38)
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = call i32 @msg_snd(i32 %40, i32 %42)
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 2
store i32 %45, i32* %7
br label %30
}

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