#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 */
struct rlimit {
  int rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_NOFILE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
void close_all() {
  struct rlimit rlim;
  rlim.rlim_cur = 9999;
  getrlimit(RLIMIT_NOFILE, &rlim);
  int i, n;
  for (i = 0, n = (int)rlim.rlim_cur; i < n; i++)
    close(i);
}


x86 assembly (clang, -O0):
<close_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x270f,-0x8(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <getrlimit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1170 <close_all+0x50>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114e <close_all+0x2e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_all>:
push   %rbp
push   %rbx
push   %rax
movl   $0x270f,(%rsp)
mov    0x2eb7(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <getrlimit@plt>
mov    (%rsp),%ebp
test   %ebp,%ebp
jle    115e <close_all+0x3e>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
call   1030 <close@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1150 <close_all+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i32 }
@RLIMIT_NOFILE = global i32 0
define void @close_all() {
%1 = alloca %struct.rlimit
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 9999, i32* %4
%5 = load i32, i32* @RLIMIT_NOFILE
%6 = call i32 @getrlimit(i32 %5, %struct.rlimit* %1)
store i32 0, i32* %2
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%8 = load i32, i32* %7
store i32 %8, i32* %3
br label %9
9: ; preds = %16, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
br label %16
16: ; preds = %13
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %9
19: ; preds = %9
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32 }
@RLIMIT_NOFILE = global i32 0
define void @close_all() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
store i32 9999, i32* %3
%4 = load i32, i32* @RLIMIT_NOFILE
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %1)
%6 = load i32, i32* %3
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ 0, %0 ]
%10 = call i32 @close(i32 %9)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, %6
br i1 %12, label %13, label %8
13: ; preds = %8, %0
ret void
}