#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *, int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ **);
void output_close(FILE *out[], int ct) {
  for (int i = 0; i < ct; i++)
    if (fclose(out[i]))
      fatal("error closing file: %s", errno);
  free(out);
}


x86 assembly (clang, -O0):
<output_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1195 <output_close+0x65>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1182 <output_close+0x52>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1050 <fatal@plt>
jmp    1187 <output_close+0x57>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <output_close+0x16>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_close>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
test   %esi,%esi
jle    1185 <output_close+0x55>
mov    %esi,%r12d
xor    %ebx,%ebx
mov    0x2e94(%rip),%r13
lea    0xead(%rip),%r14
jmp    1169 <output_close+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r12
je     1185 <output_close+0x55>
mov    (%r15,%rbx,8),%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1160 <output_close+0x30>
mov    0x0(%r13),%esi
mov    %r14,%rdi
call   1050 <fatal@plt>
jmp    1160 <output_close+0x30>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"error closing file: %s\00"
@errno = global i32 0
define void @output_close(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
store i32** %0, i32*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %22, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = load i32**, i32*** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32*, i32** %11, i64 %13
%15 = load i32*, i32** %14
%16 = call i64 @fclose(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* @errno
%20 = call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %6
25: ; preds = %6
%26 = load i32**, i32*** %3
%27 = call i32 @free(i32** %26)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"error closing file: %s\00"
@errno = global i32 0
define void @output_close(i32** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %8
6: ; preds = %17, %2
%7 = tail call i32 @free(i32** %0)
ret void
8: ; preds = %4, %17
%9 = phi i64 [ 0, %4 ], [ %18, %17 ]
%10 = getelementptr inbounds i32*, i32** %0, i64 %9
%11 = load i32*, i32** %10
%12 = tail call i64 @fclose(i32* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* @errno
%16 = tail call i32 @fatal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %8, %14
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %5
br i1 %19, label %6, label %8
}