#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 close(int);
int /*<<< orphan*/ exit_if(int, char *);
void close_pipes(int *pipes, int size, int leave_open) {
  int pipe;
  for (int a = 0; a < size; a++) {
    for (int b = 0; b < 2; b++) {
      pipe = *(pipes + a * 2 + b);
      if (pipe != leave_open) {
        exit_if(close(pipe) == -1, "Error closing file");
      }
    }
  }
}


x86 assembly (clang, -O0):
<close_pipes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c5 <close_pipes+0xa5>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    11b2 <close_pipes+0x92>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     119f <close_pipes+0x7f>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe66(%rip),%rsi
call   1030 <exit_if@plt>
jmp    11a4 <close_pipes+0x84>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <close_pipes+0x2c>
jmp    11b7 <close_pipes+0x97>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <close_pipes+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_pipes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1188 <close_pipes+0x68>
mov    %edx,%r12d
mov    %rdi,%rbx
mov    %esi,%r15d
xor    %ebp,%ebp
lea    0xec2(%rip),%r14
jmp    1149 <close_pipes+0x29>
add    $0x1,%rbp
cmp    %rbp,%r15
je     1188 <close_pipes+0x68>
mov    (%rbx,%rbp,8),%edi
cmp    %r12d,%edi
je     1167 <close_pipes+0x47>
call   1040 <close@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
mov    %r14,%rsi
call   1030 <exit_if@plt>
mov    0x4(%rbx,%rbp,8),%edi
cmp    %r12d,%edi
je     1140 <close_pipes+0x20>
call   1040 <close@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
mov    %r14,%rsi
call   1030 <exit_if@plt>
jmp    1140 <close_pipes+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Error closing file\00"
define void @close_pipes(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %10
10: ; preds = %42, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %45
14: ; preds = %10
store i32 0, i32* %9
br label %15
15: ; preds = %38, %14
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i32*, i32** %4
%20 = load i32, i32* %8
%21 = mul nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %19, i64 %22
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %18
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
%34 = icmp eq i32 %33, -1
%35 = zext i1 %34 to i32
%36 = call i32 @exit_if(i32 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %31, %18
br label %38
38: ; preds = %37
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %15
41: ; preds = %15
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %10
45: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Error closing file\00"
define void @close_pipes(i32* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %28
%8 = phi i64 [ 0, %5 ], [ %29, %28 ]
%9 = shl nuw nsw i64 %8, 1
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, %2
br i1 %12, label %19, label %14
13: ; preds = %28, %3
ret void
14: ; preds = %7
%15 = tail call i32 @close(i32 %11)
%16 = icmp eq i32 %15, -1
%17 = zext i1 %16 to i32
%18 = tail call i32 @exit_if(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %7, %14
%20 = getelementptr inbounds i32, i32* %10, i64 1
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, %2
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = tail call i32 @close(i32 %21)
%25 = icmp eq i32 %24, -1
%26 = zext i1 %25 to i32
%27 = tail call i32 @exit_if(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %23, %19
%29 = add nuw nsw i64 %8, 1
%30 = icmp eq i64 %29, %6
br i1 %30, label %13, label %7
}