#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 STDERR_FILENO;
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ _SC_OPEN_MAX;
int /*<<< orphan*/ close(int);
int sysconf(int /*<<< orphan*/);
void initfds(void) {
  int fd;
  fd = (((STDERR_FILENO) < (STDIN_FILENO)) ? (STDIN_FILENO) : (STDERR_FILENO));
  fd = (((fd) < (STDOUT_FILENO)) ? (STDOUT_FILENO) : (fd));
  for (fd = fd + 1; fd < sysconf(_SC_OPEN_MAX); fd++)
    close(fd);
}


x86 assembly (clang, -O0):
<initfds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%eax
jge    1151 <initfds+0x31>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
jmp    115d <initfds+0x3d>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%eax
jge    1186 <initfds+0x66>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    118c <initfds+0x6c>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    11d2 <initfds+0xb2>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    119b <initfds+0x7b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initfds>:
push   %r14
push   %rbx
push   %rax
mov    0x2ea5(%rip),%rax
mov    (%rax),%ebx
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ebx
cmovl  %eax,%ebx
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%ebx
cmovl  %eax,%ebx
add    $0x1,%ebx
mov    0x2e85(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%edi
call   1040 <sysconf@plt>
cmp    %eax,%ebx
jge    1178 <initfds+0x58>
mov    %ebx,%edi
call   1030 <close@plt>
add    $0x1,%ebx
jmp    1160 <initfds+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@STDERR_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@_SC_OPEN_MAX = global i32 0
define void @initfds() {
%1 = alloca i32
%2 = load i32, i32* @STDERR_FILENO
%3 = load i32, i32* @STDIN_FILENO
%4 = icmp slt i32 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i32, i32* @STDIN_FILENO
br label %9
7: ; preds = %0
%8 = load i32, i32* @STDERR_FILENO
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ %6, %5 ], [ %8, %7 ]
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = load i32, i32* @STDOUT_FILENO
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i32, i32* @STDOUT_FILENO
br label %18
16: ; preds = %9
%17 = load i32, i32* %1
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ %15, %14 ], [ %17, %16 ]
store i32 %19, i32* %1
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
br label %22
22: ; preds = %30, %18
%23 = load i32, i32* %1
%24 = load i32, i32* @_SC_OPEN_MAX
%25 = call i32 @sysconf(i32 %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* %1
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
store i32 %32, i32* %1
br label %22
33: ; preds = %22
ret void
}

LLVM IR (-O2):
@STDERR_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@_SC_OPEN_MAX = global i32 0
define void @initfds() {
%1 = load i32, i32* @STDERR_FILENO
%2 = load i32, i32* @STDIN_FILENO
%3 = icmp slt i32 %1, %2
%4 = select i1 %3, i32 %2, i32 %1
%5 = load i32, i32* @STDOUT_FILENO
%6 = icmp slt i32 %4, %5
%7 = select i1 %6, i32 %5, i32 %4
%8 = add nsw i32 %7, 1
%9 = load i32, i32* @_SC_OPEN_MAX
%10 = tail call i32 @sysconf(i32 %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %19
12: ; preds = %0, %12
%13 = phi i32 [ %15, %12 ], [ %8, %0 ]
%14 = tail call i32 @close(i32 %13)
%15 = add nsw i32 %13, 1
%16 = load i32, i32* @_SC_OPEN_MAX
%17 = tail call i32 @sysconf(i32 %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %12, label %19
19: ; preds = %12, %0
ret void
}