#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*/ close(int const);
int tor_log_get_sigsafe_err_fds(int const **);
int /*<<< orphan*/ tor_log_set_sigsafe_err_fds(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/);
void tor_log_close_sigsafe_err_fds(void) {
  int n_fds, i;
  const int *fds = NULL;
  n_fds = tor_log_get_sigsafe_err_fds(&fds);
  for (i = 0; i < n_fds; ++i) {
    (void)close(fds[i]);
  }
  tor_log_set_sigsafe_err_fds(NULL, 0);
}


x86 assembly (clang, -O0):
<tor_log_close_sigsafe_err_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <tor_log_get_sigsafe_err_fds@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117d <tor_log_close_sigsafe_err_fds+0x4d>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1153 <tor_log_close_sigsafe_err_fds+0x23>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <tor_log_set_sigsafe_err_fds@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tor_log_close_sigsafe_err_fds>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1030 <tor_log_get_sigsafe_err_fds@plt>
test   %eax,%eax
jle    1165 <tor_log_close_sigsafe_err_fds+0x35>
mov    %eax,%r14d
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp),%rax
mov    (%rax,%rbx,4),%edi
call   1040 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <tor_log_close_sigsafe_err_fds+0x20>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <tor_log_set_sigsafe_err_fds@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @tor_log_close_sigsafe_err_fds() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32* null, i32** %3
%4 = call i32 @tor_log_get_sigsafe_err_fds(i32** %3)
store i32 %4, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %16, %0
%6 = load i32, i32* %2
%7 = load i32, i32* %1
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %5
%10 = load i32*, i32** %3
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %10, i64 %12
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
br label %16
16: ; preds = %9
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %5
19: ; preds = %5
%20 = call i32 @tor_log_set_sigsafe_err_fds(i32* null, i32 0)
ret void
}

LLVM IR (-O2):
define void @tor_log_close_sigsafe_err_fds() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
store i32* null, i32** %1
%3 = call i32 @tor_log_get_sigsafe_err_fds(i32** %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = load i32*, i32** %1
%10 = getelementptr inbounds i32, i32* %9, i64 %8
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %15, label %7
15: ; preds = %7, %0
%16 = call i32 @tor_log_set_sigsafe_err_fds(i32* null, i32 0)
ret void
}