#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_SUCCESS;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int pclose(int /*<<< orphan*/ *);
int close_pipes(FILE **p, size_t i) {
  int ret = EXIT_SUCCESS;
  size_t j;
  for (j = 0; j < i; j++) {
    int r = pclose(p[j]);
    if (WIFEXITED(r))
      ret |= WEXITSTATUS(r);
    else
      ret |= 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<close_pipes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ba <close_pipes+0x8a>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <pclose@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     119b <close_pipes+0x6b>
mov    -0x24(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <close_pipes+0x74>
mov    -0x14(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a9 <close_pipes+0x79>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1154 <close_pipes+0x24>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_pipes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ea1(%rip),%rax
mov    (%rax),%ebx
test   %rsi,%rsi
je     1182 <close_pipes+0x52>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    1163 <close_pipes+0x33>
mov    %r12d,%edi
call   1040 <WEXITSTATUS@plt>
or     %eax,%ebx
add    $0x1,%rbp
cmp    %rbp,%r14
je     1182 <close_pipes+0x52>
mov    (%r15,%rbp,8),%rdi
call   1030 <pclose@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1050 <WIFEXITED@plt>
test   %rax,%rax
jne    1150 <close_pipes+0x20>
mov    $0x1,%eax
jmp    1158 <close_pipes+0x28>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
define i32 @close_pipes(i32** %0, i64 %1) {
%3 = alloca i32**
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store i32** %0, i32*** %3
store i64 %1, i64* %4
%8 = load i32, i32* @EXIT_SUCCESS
store i32 %8, i32* %5
store i64 0, i64* %6
br label %9
9: ; preds = %31, %2
%10 = load i64, i64* %6
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i32**, i32*** %3
%15 = load i64, i64* %6
%16 = getelementptr inbounds i32*, i32** %14, i64 %15
%17 = load i32*, i32** %16
%18 = call i32 @pclose(i32* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = call i64 @WIFEXITED(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load i32, i32* %7
%24 = call i32 @WEXITSTATUS(i32 %23)
%25 = load i32, i32* %5
%26 = or i32 %25, %24
store i32 %26, i32* %5
br label %30
27: ; preds = %13
%28 = load i32, i32* %5
%29 = or i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %27, %22
br label %31
31: ; preds = %30
%32 = load i64, i64* %6
%33 = add i64 %32, 1
store i64 %33, i64* %6
br label %9
34: ; preds = %9
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
define i32 @close_pipes(i32** nocapture %0, i64 %1) {
%3 = load i32, i32* @EXIT_SUCCESS
%4 = icmp eq i64 %1, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %15
%6 = phi i32 [ %17, %15 ], [ %3, %2 ]
%7 = phi i64 [ %18, %15 ], [ 0, %2 ]
%8 = getelementptr inbounds i32*, i32** %0, i64 %7
%9 = load i32*, i32** %8
%10 = tail call i32 @pclose(i32* %9)
%11 = tail call i64 @WIFEXITED(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = tail call i32 @WEXITSTATUS(i32 %10)
br label %15
15: ; preds = %5, %13
%16 = phi i32 [ %14, %13 ], [ 1, %5 ]
%17 = or i32 %16, %6
%18 = add nuw i64 %7, 1
%19 = icmp eq i64 %18, %1
br i1 %19, label %20, label %5
20: ; preds = %15, %2
%21 = phi i32 [ %3, %2 ], [ %17, %15 ]
ret i32 %21
}