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

/* Variables and functions */
size_t FD_SETSIZE;
int *__FDS_BITS(int /*<<< orphan*/ const *);
size_t __NFDBITS;
void fd_set_and(fd_set *res, fd_set const *a, fd_set const *b) {
  for (size_t i = 0; i < FD_SETSIZE / __NFDBITS; i++) {
    __FDS_BITS(res)[i] = __FDS_BITS(a)[i] & __FDS_BITS(b)[i];
  }
}


x86 assembly (clang, -O0):
<fd_set_and>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%rax
mov    0x2e8b(%rip),%rcx
xor    %edx,%edx
divq   (%rcx)
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    11aa <fd_set_and+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <__FDS_BITS@plt>
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <__FDS_BITS@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%eax
mov    -0x20(%rbp),%rdx
and    (%rcx,%rdx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <__FDS_BITS@plt>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <fd_set_and+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_set_and>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ebe(%rip),%rcx
mov    0x2ea7(%rip),%r13
mov    0x0(%r13),%rax
cmp    (%rcx),%rax
ja     1195 <fd_set_and+0x85>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %ebp,%ebp
jmp    114a <fd_set_and+0x3a>
nop
xor    %edx,%edx
div    %rcx
cmp    %rax,%rbp
jae    1195 <fd_set_and+0x85>
mov    %r15,%rdi
call   1030 <__FDS_BITS@plt>
mov    (%rax,%rbp,4),%r12d
mov    %r14,%rdi
call   1030 <__FDS_BITS@plt>
and    (%rax,%rbp,4),%r12d
mov    %rbx,%rdi
call   1030 <__FDS_BITS@plt>
mov    %r12d,(%rax,%rbp,4)
add    $0x1,%rbp
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x0(%r13),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
jne    1140 <fd_set_and+0x30>
xor    %edx,%edx
div    %ecx
cmp    %rax,%rbp
jb     114a <fd_set_and+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@FD_SETSIZE = global i64 0
@__NFDBITS = global i64 0
define void @fd_set_and(i32* %0, i32* %1, i32* %2) {
%4 = load i64, i64* @FD_SETSIZE
%5 = load i64, i64* @__NFDBITS
%6 = icmp ugt i64 %5, %4
br i1 %6, label %7, label %8
7: ; preds = %8, %3
ret void
8: ; preds = %3, %8
%9 = phi i64 [ %19, %8 ], [ 0, %3 ]
%10 = tail call i32* @__FDS_BITS(i32* %1)
%11 = getelementptr inbounds i32, i32* %10, i64 %9
%12 = load i32, i32* %11
%13 = tail call i32* @__FDS_BITS(i32* %2)
%14 = getelementptr inbounds i32, i32* %13, i64 %9
%15 = load i32, i32* %14
%16 = and i32 %15, %12
%17 = tail call i32* @__FDS_BITS(i32* %0)
%18 = getelementptr inbounds i32, i32* %17, i64 %9
store i32 %16, i32* %18
%19 = add nuw i64 %9, 1
%20 = load i64, i64* @FD_SETSIZE
%21 = load i64, i64* @__NFDBITS
%22 = udiv i64 %20, %21
%23 = icmp ult i64 %19, %22
br i1 %23, label %8, label %7
}