#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;
int mq_close(scalar_t__);
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-2"
           ": "
           "send_receive: "
           "expected an 'a'");
    return 2;
  }
  mqdes = mq_open(mqname, O_RDWR, 0, 0);
  if (mqdes == (mqd_t)-1) {
    perror("unexpected error: "
           "mq_unlink"
           " "
           "2-2"
           ": "
           "mq_open");
    return 2;
  }
  rval = send_receive(read_pipe, write_pipe, 'b', &reply);
  if (rval) {
    return rval;
  }
  if (reply != 'c') {
    printf("unexpected error: "
           "mq_unlink"
           " "
           "2-2"
           ": "
           "send_receive: "
           "expected a 'c'\n");
    return 2;
  }
  if (mq_close(mqdes) == -1) {
    perror("unexpected error: "
           "mq_unlink"
           " "
           "2-2"
           ": "
           "mq_close");
    return 2;
  }
  rval = send_receive(read_pipe, write_pipe, 'd', NULL);
  if (rval) {
    return rval;
  }
  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   1060 <send_receive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     118b <child_process+0x3b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129b <child_process+0x14b>
movsbl -0x25(%rbp),%eax
cmp    $0x61,%eax
je     11b0 <child_process+0x60>
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129b <child_process+0x14b>
mov    -0x10(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <mq_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11ed <child_process+0x9d>
lea    0xe63(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    129b <child_process+0x14b>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x62,%edx
lea    -0x25(%rbp),%rcx
call   1060 <send_receive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1219 <child_process+0xc9>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129b <child_process+0x14b>
movsbl -0x25(%rbp),%eax
cmp    $0x63,%eax
je     123e <child_process+0xee>
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129b <child_process+0x14b>
mov    -0x20(%rbp),%rdi
call   1040 <mq_close@plt>
cmp    $0xffffffff,%eax
jne    1268 <child_process+0x118>
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    129b <child_process+0x14b>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x64,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <send_receive@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1294 <child_process+0x144>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    129b <child_process+0x14b>
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,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x7(%rsp),%rcx
mov    %esi,%edi
mov    %edx,%esi
xor    %edx,%edx
call   1070 <send_receive@plt>
test   %eax,%eax
jne    11f8 <child_process+0x98>
cmpb   $0x61,0x7(%rsp)
jne    11e7 <child_process+0x87>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1211 <child_process+0xb1>
mov    %rax,%r14
lea    0x7(%rsp),%rcx
mov    %ebp,%edi
mov    %r15d,%esi
mov    $0x62,%edx
call   1070 <send_receive@plt>
test   %eax,%eax
jne    11f8 <child_process+0x98>
cmpb   $0x63,0x7(%rsp)
jne    1203 <child_process+0xa3>
mov    %r14,%rdi
call   1050 <mq_close@plt>
cmp    $0xffffffff,%eax
je     121f <child_process+0xbf>
mov    %ebp,%edi
mov    %r15d,%esi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1070 <send_receive@plt>
jmp    11f8 <child_process+0x98>
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
jmp    11f3 <child_process+0x93>
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
jmp    11f3 <child_process+0x93>
lea    0xe42(%rip),%rdi
jmp    1218 <child_process+0xb8>

LLVM IR (-O0):
@.str = [63 x i8] c"unexpected error: mq_unlink 2-2: send_receive: expected an 'a'\00"
@O_RDWR = global i32 0
@.str.1 = [41 x i8] c"unexpected error: mq_unlink 2-2: mq_open\00"
@.str.2 = [63 x i8] c"unexpected error: mq_unlink 2-2: send_receive: expected a 'c'\0A\00"
@.str.3 = [42 x i8] c"unexpected error: mq_unlink 2-2: mq_close\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 %61
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 ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %4
br label %61
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 %61
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* %10)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = load i32, i32* %9
store i32 %39, i32* %4
br label %61
40: ; preds = %32
%41 = load i8, i8* %10
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 99
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %4
br label %61
46: ; preds = %40
%47 = load i64, i64* %8
%48 = call i32 @mq_close(i64 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %4
br label %61
52: ; preds = %46
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = call i32 @send_receive(i32 %53, i32 %54, i8 signext 100, i8* null)
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = load i32, i32* %9
store i32 %59, i32* %4
br label %61
60: ; preds = %52
store i32 0, i32* %4
br label %61
61: ; preds = %60, %58, %50, %44, %38, %30, %22, %16
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [63 x i8] c"unexpected error: mq_unlink 2-2: send_receive: expected an 'a'\00"
@O_RDWR = global i32 0
@.str.1 = [41 x i8] c"unexpected error: mq_unlink 2-2: mq_open\00"
@.str.3 = [42 x i8] c"unexpected error: mq_unlink 2-2: mq_close\00"
@str = [62 x i8] c"unexpected error: mq_unlink 2-2: send_receive: expected a 'c'\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 %33
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 @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
br label %33
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 %33
18: ; preds = %12
%19 = call i32 @send_receive(i32 %1, i32 %2, i8 signext 98, i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i8, i8* %4
%23 = icmp eq i8 %22, 99
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
br label %33
26: ; preds = %21
%27 = call i32 @mq_close(i64 %14)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %33
31: ; preds = %26
%32 = call i32 @send_receive(i32 %1, i32 %2, i8 signext 100, i8* null)
br label %33
33: ; preds = %31, %18, %3, %29, %24, %16, %10
%34 = phi i32 [ 2, %10 ], [ 2, %16 ], [ 2, %24 ], [ 2, %29 ], [ %5, %3 ], [ %19, %18 ], [ %32, %31 ]
ret i32 %34
}