#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int write(int, char *, int);
int send_receive(int read_pipe, int write_pipe, char send, char *reply) {
  ssize_t bytes;
  if (send) {
    bytes = write(write_pipe, &send, 1);
    if (bytes == -1) {
      perror("unexpected error: "
             "mq_unlink"
             " "
             "2-2"
             ": "
             "write fd[1]");
      return 2;
    }
  }
  if (reply) {
    bytes = read(read_pipe, reply, 1);
    if (bytes == -1) {
      perror("unexpected error: "
             "mq_unlink"
             " "
             "2-2"
             ": "
             "read fd[0]");
      return 2;
    } else if (bytes == 0) {
      printf("unexpected error: "
             "mq_unlink"
             " "
             "2-2"
             ": "
             "read: EOF\n");
      return 2;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,-0xd(%rbp)
je     119c <send_receive+0x5c>
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1197 <send_receive+0x57>
lea    0xe7a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1210 <send_receive+0xd0>
jmp    119c <send_receive+0x5c>
cmpq   $0x0,-0x18(%rbp)
je     1209 <send_receive+0xc9>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11dd <send_receive+0x9d>
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1210 <send_receive+0xd0>
cmpl   $0x0,-0x1c(%rbp)
jne    11ff <send_receive+0xbf>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1210 <send_receive+0xd0>
jmp    1204 <send_receive+0xc4>
jmp    1209 <send_receive+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_receive>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %edi,%r14d
mov    %dl,0xf(%rsp)
test   %dl,%dl
je     116f <send_receive+0x2f>
lea    0xf(%rsp),%rax
mov    %esi,%edi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     11b9 <send_receive+0x79>
xor    %ebp,%ebp
test   %rbx,%rbx
je     11ae <send_receive+0x6e>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
je     119d <send_receive+0x5d>
cmp    $0xffffffff,%eax
jne    11ae <send_receive+0x6e>
lea    0xe97(%rip),%rdi
call   1060 <perror@plt>
jmp    11a9 <send_receive+0x69>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
jmp    11a9 <send_receive+0x69>

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

LLVM IR (-O2):
@.str = [45 x i8] c"unexpected error: mq_unlink 2-2: write fd[1]\00"
@.str.1 = [44 x i8] c"unexpected error: mq_unlink 2-2: read fd[0]\00"
@str = [43 x i8] c"unexpected error: mq_unlink 2-2: read: EOF\00"
define i32 @send_receive(i32 %0, i32 %1, i8 signext %2, i8* %3) {
%5 = alloca i8
store i8 %2, i8* %5
%6 = icmp eq i8 %2, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = call i32 @write(i32 %1, i8* %5, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %20
12: ; preds = %7, %4
%13 = icmp eq i8* %3, null
br i1 %13, label %20, label %14
14: ; preds = %12
%15 = tail call i32 @read(i32 %0, i8* %3, i32 1)
switch i32 %15, label %20 [
i32 -1, label %16
i32 0, label %18
]
16: ; preds = %14
%17 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %12, %14, %18, %16, %10
%21 = phi i32 [ 2, %10 ], [ 2, %16 ], [ 2, %18 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %21
}