#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_set_clear(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *);
int fd_set_build(int s, fd_set *rd, fd_set *wr, fd_set *er) {
  fd_set_clear(rd, wr, er);
  if (rd)
    FD_SET(s, rd);
  if (wr)
    FD_SET(s, wr);
  if (er)
    FD_SET(s, er);
  return 0;
}


x86 assembly (clang, -O0):
<fd_set_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <fd_set_clear@plt>
cmpq   $0x0,-0x10(%rbp)
je     115f <fd_set_build+0x3f>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_SET@plt>
cmpq   $0x0,-0x18(%rbp)
je     1176 <fd_set_build+0x56>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <FD_SET@plt>
cmpq   $0x0,-0x20(%rbp)
je     118d <fd_set_build+0x6d>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <FD_SET@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_set_build>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1040 <fd_set_clear@plt>
test   %rbx,%rbx
je     1151 <fd_set_build+0x31>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <FD_SET@plt>
test   %rbp,%rbp
je     1161 <fd_set_build+0x41>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <FD_SET@plt>
test   %r15,%r15
je     1171 <fd_set_build+0x51>
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <FD_SET@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fd_set_build(i32 %0, i32* %1, i32* %2, i32* %3) {
%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* %3, i32** %8
%9 = load i32*, i32** %6
%10 = load i32*, i32** %7
%11 = load i32*, i32** %8
%12 = call i32 @fd_set_clear(i32* %9, i32* %10, i32* %11)
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i32, i32* %5
%17 = load i32*, i32** %6
%18 = call i32 @FD_SET(i32 %16, i32* %17)
br label %19
19: ; preds = %15, %4
%20 = load i32*, i32** %7
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %5
%24 = load i32*, i32** %7
%25 = call i32 @FD_SET(i32 %23, i32* %24)
br label %26
26: ; preds = %22, %19
%27 = load i32*, i32** %8
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %5
%31 = load i32*, i32** %8
%32 = call i32 @FD_SET(i32 %30, i32* %31)
br label %33
33: ; preds = %29, %26
ret i32 0
}

LLVM IR (-O2):
define i32 @fd_set_build(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i32 @fd_set_clear(i32* %1, i32* %2, i32* %3)
%6 = icmp eq i32* %1, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @FD_SET(i32 %0, i32* %1)
br label %9
9: ; preds = %7, %4
%10 = icmp eq i32* %2, null
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @FD_SET(i32 %0, i32* %2)
br label %13
13: ; preds = %11, %9
%14 = icmp eq i32* %3, null
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = tail call i32 @FD_SET(i32 %0, i32* %3)
br label %17
17: ; preds = %15, %13
ret i32 0
}