#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 errno;
int close_fds(int fds[], size_t count) {
  for (int index = 0; index < count; ++index) {
    if (fds[index] != -1) {
      if (close(fds[index]) == -1) {
        return errno;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<close_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1189 <close_fds+0x79>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     1176 <close_fds+0x66>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1171 <close_fds+0x61>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <close_fds+0x80>
jmp    1176 <close_fds+0x66>
jmp    117b <close_fds+0x6b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <close_fds+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_fds>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1157 <close_fds+0x47>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
jmp    1139 <close_fds+0x29>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%r15
je     1157 <close_fds+0x47>
mov    (%r14,%rbx,4),%edi
cmp    $0xffffffff,%edi
je     1130 <close_fds+0x20>
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1130 <close_fds+0x20>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
jmp    1159 <close_fds+0x49>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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