#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 /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int _fds_add(fd_set *lhs, fd_set *rhs, int nfds) {
  int fd;
  for (fd = 0; fd < nfds; fd++) {
    if (FD_ISSET(fd, rhs)) {
      FD_SET(fd, lhs);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<_fds_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117b <_fds_add+0x5b>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1168 <_fds_add+0x48>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <FD_SET@plt>
jmp    116d <_fds_add+0x4d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <_fds_add+0x1a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fds_add>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1162 <_fds_add+0x42>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    1147 <_fds_add+0x27>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%ebx
je     1162 <_fds_add+0x42>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1140 <_fds_add+0x20>
mov    %ebp,%edi
mov    %r15,%rsi
call   1040 <FD_SET@plt>
jmp    1140 <_fds_add+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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