#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 */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int _fds_check2(fd_set *fds, fd_set *chk, int nfds) {
  int fd;
  for (fd = 0; fd < nfds; fd++) {
    if (FD_ISSET(fd, chk) && FD_ISSET(fd, fds)) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<_fds_check2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1181 <_fds_check2+0x71>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     116e <_fds_check2+0x5e>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     116e <_fds_check2+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    1188 <_fds_check2+0x78>
jmp    1173 <_fds_check2+0x63>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <_fds_check2+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fds_check2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    115c <_fds_check2+0x4c>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    1137 <_fds_check2+0x27>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%ebx
je     115c <_fds_check2+0x4c>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1130 <_fds_check2+0x20>
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1130 <_fds_check2+0x20>
mov    $0x1,%eax
jmp    115e <_fds_check2+0x4e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_fds_check2(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %25, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i32, i32* %8
%15 = load i32*, i32** %6
%16 = call i64 @FD_ISSET(i32 %14, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32, i32* %8
%20 = load i32*, i32** %5
%21 = call i64 @FD_ISSET(i32 %19, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %4
br label %29
24: ; preds = %18, %13
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %9
28: ; preds = %9
store i32 0, i32* %4
br label %29
29: ; preds = %28, %23
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @_fds_check2(i32* %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %15
5: ; preds = %3, %12
%6 = phi i32 [ %13, %12 ], [ 0, %3 ]
%7 = tail call i64 @FD_ISSET(i32 %6, i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i64 @FD_ISSET(i32 %6, i32* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %5, %9
%13 = add nuw nsw i32 %6, 1
%14 = icmp eq i32 %13, %2
br i1 %14, label %15, label %5
15: ; preds = %9, %12, %3
%16 = phi i32 [ 0, %3 ], [ 0, %12 ], [ 1, %9 ]
ret i32 %16
}