#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*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int INT_MIN;
int init_fdset(const int *const fds, size_t nfds, fd_set *fdset) {
  int maxfd = INT_MIN;
  FD_ZERO(fdset);
  for (size_t i = 0; i < nfds; i++) {
    int fd = fds[i];
    FD_SET(fd, fdset);
    if (fd > maxfd)
      maxfd = fd;
  }
  return maxfd;
}


x86 assembly (clang, -O0):
<init_fdset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <FD_ZERO@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a1 <init_fdset+0x81>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <FD_SET@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    118b <init_fdset+0x6b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1190 <init_fdset+0x70>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1151 <init_fdset+0x31>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_fdset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2ead(%rip),%rax
mov    (%rax),%r13d
mov    %rdx,%rdi
call   1030 <FD_ZERO@plt>
test   %r15,%r15
je     116e <init_fdset+0x4e>
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r12,%rbx,4),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <FD_SET@plt>
cmp    %r13d,%ebp
cmovg  %ebp,%r13d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <init_fdset+0x30>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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