#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_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
char passThrough(int, int);
int /*<<< orphan*/ perror(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char passAll(int a_in, int a_out, int b_in, int b_out) {
  int maxfd = a_in > b_in ? a_in : b_in;
  fd_set fds;
  FD_ZERO(&fds);
  char a_EOF = 0;
  char b_EOF = 0;
  while (1) {
    if (!a_EOF)
      FD_SET(a_in, &fds);
    if (!b_EOF)
      FD_SET(b_in, &fds);
    int res = select(maxfd + 1, &fds, NULL, NULL, NULL);
    if (res < 0) {
      perror("select()");
      exit(1);
    } else if (FD_ISSET(a_in, &fds)) {
      a_EOF = passThrough(a_in, b_out);
      FD_CLR(a_in, &fds);
    } else if (FD_ISSET(b_in, &fds)) {
      b_EOF = passThrough(b_in, a_out);
      FD_CLR(b_in, &fds);
    }
  }
}


x86 assembly (clang, -O0):
<passAll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11ab <passAll+0x2b>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11b1 <passAll+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <FD_ZERO@plt>
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x1a(%rbp)
cmpb   $0x0,-0x19(%rbp)
jne    11de <passAll+0x5e>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10a0 <FD_SET@plt>
cmpb   $0x0,-0x1a(%rbp)
jne    11f4 <passAll+0x74>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1060 <select@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1231 <passAll+0xb1>
lea    0xdde(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1266 <passAll+0xe6>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <passThrough@plt>
mov    %al,-0x19(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1080 <FD_CLR@plt>
jmp    129b <passAll+0x11b>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1296 <passAll+0x116>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <passThrough@plt>
mov    %al,-0x1a(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1080 <FD_CLR@plt>
jmp    129b <passAll+0x11b>
jmp    12a0 <passAll+0x120>
jmp    11c8 <passAll+0x48>

x86 assembly (clang, -O2):
<passAll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x10(%rsp)
mov    %edx,%r13d
mov    %esi,0xc(%rsp)
mov    %edi,%ebx
cmp    %edx,%edi
mov    %edx,%r12d
cmovg  %edi,%r12d
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <FD_ZERO@plt>
add    $0x1,%r12d
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11e0 <passAll+0x60>
mov    %ebx,%edi
mov    0x10(%rsp),%esi
call   1030 <passThrough@plt>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %rbp,%rsi
call   1080 <FD_CLR@plt>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r15b,%r15b
je     1240 <passAll+0xc0>
test   %r14b,%r14b
je     124f <passAll+0xcf>
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <select@plt>
test   %eax,%eax
js     125c <passAll+0xdc>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
jne    11bd <passAll+0x3d>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     11e0 <passAll+0x60>
mov    %r13d,%edi
mov    0xc(%rsp),%esi
call   1030 <passThrough@plt>
mov    %eax,%r14d
mov    %r13d,%edi
jmp    11cd <passAll+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
call   10a0 <FD_SET@plt>
test   %r14b,%r14b
jne    11ea <passAll+0x6a>
mov    %r13d,%edi
mov    %rbp,%rsi
call   10a0 <FD_SET@plt>
jmp    11ea <passAll+0x6a>
lea    0xd9d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"select()\00"
define signext i8 @passAll(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
%13 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %5
%15 = load i32, i32* %7
%16 = icmp sgt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %5
br label %21
19: ; preds = %4
%20 = load i32, i32* %7
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
store i32 %22, i32* %9
%23 = call i32 @FD_ZERO(i32* %10)
store i8 0, i8* %11
store i8 0, i8* %12
br label %24
24: ; preds = %21, %67
%25 = load i8, i8* %11
%26 = icmp ne i8 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %5
%29 = call i32 @FD_SET(i32 %28, i32* %10)
br label %30
30: ; preds = %27, %24
%31 = load i8, i8* %12
%32 = icmp ne i8 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* %7
%35 = call i32 @FD_SET(i32 %34, i32* %10)
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
%39 = call i32 @select(i32 %38, i32* %10, i32* null, i32* null, i32* null)
store i32 %39, i32* %13
%40 = load i32, i32* %13
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = load i32, i32* %5
%47 = call i64 @FD_ISSET(i32 %46, i32* %10)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %45
%50 = load i32, i32* %5
%51 = load i32, i32* %8
%52 = call signext i8 @passThrough(i32 %50, i32 %51)
store i8 %52, i8* %11
%53 = load i32, i32* %5
%54 = call i32 @FD_CLR(i32 %53, i32* %10)
br label %66
55: ; preds = %45
%56 = load i32, i32* %7
%57 = call i64 @FD_ISSET(i32 %56, i32* %10)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %55
%60 = load i32, i32* %7
%61 = load i32, i32* %6
%62 = call signext i8 @passThrough(i32 %60, i32 %61)
store i8 %62, i8* %12
%63 = load i32, i32* %7
%64 = call i32 @FD_CLR(i32 %63, i32* %10)
br label %65
65: ; preds = %59, %55
br label %66
66: ; preds = %65, %49
br label %67
67: ; preds = %66
br label %24
}

LLVM IR (-O2):
@.str = [9 x i8] c"select()\00"
define signext i8 @passAll(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = icmp sgt i32 %0, %2
%7 = select i1 %6, i32 %0, i32 %2
%8 = bitcast i32* %5 to i8*
%9 = call i32 @FD_ZERO(i32* %5)
%10 = add nsw i32 %7, 1
br label %11
11: ; preds = %38, %4
%12 = phi i8 [ %40, %38 ], [ 0, %4 ]
%13 = phi i8 [ %41, %38 ], [ 0, %4 ]
%14 = icmp eq i8 %13, 0
%15 = icmp eq i8 %12, 0
br label %16
16: ; preds = %11, %33
br i1 %14, label %17, label %19
17: ; preds = %16
%18 = call i32 @FD_SET(i32 %0, i32* %5)
br label %19
19: ; preds = %17, %16
br i1 %15, label %20, label %22
20: ; preds = %19
%21 = call i32 @FD_SET(i32 %2, i32* %5)
br label %22
22: ; preds = %20, %19
%23 = call i32 @select(i32 %10, i32* %5, i32* null, i32* null, i32* null)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = call i64 @FD_ISSET(i32 %0, i32* %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call signext i8 @passThrough(i32 %0, i32 %3)
br label %38
33: ; preds = %28
%34 = call i64 @FD_ISSET(i32 %2, i32* %5)
%35 = icmp eq i64 %34, 0
br i1 %35, label %16, label %36
36: ; preds = %33
%37 = call signext i8 @passThrough(i32 %2, i32 %1)
br label %38
38: ; preds = %36, %31
%39 = phi i32 [ %0, %31 ], [ %2, %36 ]
%40 = phi i8 [ %12, %31 ], [ %37, %36 ]
%41 = phi i8 [ %32, %31 ], [ %13, %36 ]
%42 = call i32 @FD_CLR(i32 %39, i32* %5)
br label %11
}