#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 scalar_t__ mqd_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
scalar_t__ mq_open(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                   int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int send_receive(int, int, char, char *);
int child_process(char *mqname, int read_pipe, int write_pipe) {
  mqd_t mqdes;
  int rval;
  char reply;
  rval = send_receive(read_pipe, write_pipe, 0, &reply);
  if (rval) {
    return rval;
  }
  if (reply != 'a') {
    printf("unexpected error: "
           "mq_unlink"
           " "
           "2-1"
           ": "
           "send_receive: "
           "expected an 'a'\n");
    return 2;
  }
  mqdes = mq_open(mqname, O_RDWR, 0, 0);
  if (mqdes == (mqd_t)-1) {
    perror("unexpected error: "
           "mq_unlink"
           " "
           "2-1"
           ": "
           "mq_open");
    return 2;
  }
  rval = send_receive(read_pipe, write_pipe, 'b', NULL);
  return 0;
}


x86 assembly (clang, -O0):
<child_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
xor    %edx,%edx
lea    -0x25(%rbp),%rcx
call   1050 <send_receive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     117b <child_process+0x3b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <child_process+0xbb>
movsbl -0x25(%rbp),%eax
cmp    $0x61,%eax
je     11a0 <child_process+0x60>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11fb <child_process+0xbb>
mov    -0x10(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <mq_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11dd <child_process+0x9d>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11fb <child_process+0xbb>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x62,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <send_receive@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_process>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x7(%rsp),%rcx
mov    %esi,%edi
mov    %edx,%esi
xor    %edx,%edx
call   1050 <send_receive@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11ad <child_process+0x6d>
cmpb   $0x61,0x7(%rsp)
jne    119c <child_process+0x5c>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     11ba <child_process+0x7a>
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0x62,%edx
xor    %ecx,%ecx
call   1050 <send_receive@plt>
jmp    11ad <child_process+0x6d>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
jmp    11a8 <child_process+0x68>

LLVM IR (-O0):
@.str = [64 x i8] c"unexpected error: mq_unlink 2-1: send_receive: expected an 'a'\0A\00"
@O_RDWR = global i32 0
@.str.1 = [41 x i8] c"unexpected error: mq_unlink 2-1: mq_open\00"
define i32 @child_process(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = call i32 @send_receive(i32 %11, i32 %12, i8 signext 0, i8* %10)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %9
store i32 %17, i32* %4
br label %36
18: ; preds = %3
%19 = load i8, i8* %10
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 97
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %4
br label %36
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = load i32, i32* @O_RDWR
%27 = call i64 @mq_open(i8* %25, i32 %26, i32 0, i32 0)
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = icmp eq i64 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %4
br label %36
32: ; preds = %24
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @send_receive(i32 %33, i32 %34, i8 signext 98, i8* null)
store i32 %35, i32* %9
store i32 0, i32* %4
br label %36
36: ; preds = %32, %30, %22, %16
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str.1 = [41 x i8] c"unexpected error: mq_unlink 2-1: mq_open\00"
@str = [63 x i8] c"unexpected error: mq_unlink 2-1: send_receive: expected an 'a'\00"
define i32 @child_process(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8
%5 = call i32 @send_receive(i32 %1, i32 %2, i8 signext 0, i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, 97
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
br label %20
12: ; preds = %7
%13 = load i32, i32* @O_RDWR
%14 = call i64 @mq_open(i8* %0, i32 %13, i32 0, i32 0)
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %12
%19 = call i32 @send_receive(i32 %1, i32 %2, i8 signext 98, i8* null)
br label %20
20: ; preds = %3, %18, %16, %10
%21 = phi i32 [ 2, %10 ], [ 2, %16 ], [ 0, %18 ], [ %5, %3 ]
ret i32 %21
}