#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 */

/* Variables and functions */
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int waitpid(int, int *, int /*<<< orphan*/);
int pcloseRWE(int pid, int *rwepipe) {
  int rc, status;
  close(rwepipe[0]);
  close(rwepipe[1]);
  close(rwepipe[2]);
  do {
    rc = waitpid(pid, &status, 0);
  } while (rc != 0 && !WIFEXITED(status));
  return status;
}


x86 assembly (clang, -O0):
<pcloseRWE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <close@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     1195 <pcloseRWE+0x65>
mov    -0x18(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1162 <pcloseRWE+0x32>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcloseRWE>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    (%rsi),%edi
call   1030 <close@plt>
mov    0x4(%r14),%edi
call   1030 <close@plt>
mov    0x8(%r14),%edi
call   1030 <close@plt>
lea    0x4(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %eax,%eax
je     117d <pcloseRWE+0x4d>
mov    0x4(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %eax,%eax
je     1160 <pcloseRWE+0x30>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @pcloseRWE(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
%10 = call i32 @close(i32 %9)
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i64 2
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %30, %2
%20 = load i32, i32* %3
%21 = call i32 @waitpid(i32 %20, i32* %6, i32 0)
store i32 %21, i32* %5
br label %22
22: ; preds = %19
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %6
%27 = call i32 @WIFEXITED(i32 %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br label %30
30: ; preds = %25, %22
%31 = phi i1 [ false, %22 ], [ %29, %25 ]
br i1 %31, label %19, label %32
32: ; preds = %30
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
define i32 @pcloseRWE(i32 %0, i32* nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* %1
%6 = tail call i32 @close(i32 %5)
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = load i32, i32* %7
%9 = tail call i32 @close(i32 %8)
%10 = getelementptr inbounds i32, i32* %1, i64 2
%11 = load i32, i32* %10
%12 = tail call i32 @close(i32 %11)
br label %13
13: ; preds = %16, %2
%14 = call i32 @waitpid(i32 %0, i32* %3, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* %3
%18 = call i32 @WIFEXITED(i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %13, label %20
20: ; preds = %13, %16
%21 = load i32, i32* %3
ret i32 %21
}