#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 /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ copyData(int, int, char *, int const);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ select(int const, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(void) {
  const int bufSize = 2048;
  fd_set fdSet;
  FD_ZERO(&fdSet);
  FD_SET(0, &fdSet);
  FD_SET(7, &fdSet);
  const int max_fd = 7;
  char buf[bufSize];
  while (1) {
    fd_set dup = fdSet;
    if (select(max_fd + 1, &dup, NULL, NULL, NULL) <= 0) {
      fprintf(stderr, "fd-proxy: select failure errno=%d %s\n", errno,
              strerror(errno));
      break;
    } else {
      if ((FD_ISSET(0, &dup) && copyData(0, 6, buf, bufSize)) ||
          (FD_ISSET(7, &dup) && copyData(7, 1, buf, bufSize))) {
        break;
      }
    }
  }
  return errno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x800,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
call   1090 <FD_SET@plt>
mov    $0x7,%edi
lea    -0xc(%rbp),%rsi
call   1090 <FD_SET@plt>
movl   $0x7,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
jmp    11be <main+0x4e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x8,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1060 <select@plt>
cmp    $0x0,%rax
jg     1233 <main+0xc3>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x828(%rbp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x828(%rbp),%edi
mov    -0x824(%rbp),%edx
mov    %rax,%rcx
lea    0xdd7(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12b6 <main+0x146>
xor    %edi,%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     126a <main+0xfa>
xor    %edi,%edi
mov    $0x6,%esi
lea    -0x820(%rbp),%rdx
mov    $0x800,%ecx
call   1070 <copyData@plt>
cmp    $0x0,%rax
jne    12a7 <main+0x137>
mov    $0x7,%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12ac <main+0x13c>
mov    $0x7,%edi
mov    $0x1,%esi
lea    -0x820(%rbp),%rdx
mov    $0x800,%ecx
call   1070 <copyData@plt>
cmp    $0x0,%rax
je     12ac <main+0x13c>
jmp    12b6 <main+0x146>
jmp    12b1 <main+0x141>
jmp    11b9 <main+0x49>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x818,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <FD_SET@plt>
mov    $0x7,%edi
mov    %rbx,%rsi
call   1090 <FD_SET@plt>
mov    %rsp,%r15
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x8,%edi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <select@plt>
test   %rax,%rax
jle    1259 <main+0xe9>
lea    0x8(%rsp),%rbx
lea    0x10(%rsp),%r14
jmp    1201 <main+0x91>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    $0x8,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <select@plt>
test   %rax,%rax
jle    1259 <main+0xe9>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1229 <main+0xb9>
xor    %edi,%edi
mov    $0x6,%esi
mov    %r14,%rdx
mov    $0x800,%ecx
call   1070 <copyData@plt>
test   %rax,%rax
jne    1285 <main+0x115>
mov    $0x7,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11e0 <main+0x70>
mov    $0x7,%edi
mov    $0x1,%esi
mov    %r14,%rdx
mov    $0x800,%ecx
call   1070 <copyData@plt>
test   %rax,%rax
je     11e0 <main+0x70>
jmp    1285 <main+0x115>
mov    0x2d80(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6f(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xd87(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %r15,%rsp
add    $0x818,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"fd-proxy: select failure errno=%d %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 2048, i32* %2
%7 = call i32 @FD_ZERO(i32* %3)
%8 = call i32 @FD_SET(i32 0, i32* %3)
%9 = call i32 @FD_SET(i32 7, i32* %3)
store i32 7, i32* %4
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 2048
br label %12
12: ; preds = %37, %0
br label %13
13: ; preds = %12
%14 = load i32, i32* %3
store i32 %14, i32* %6
%15 = call i64 @select(i32 8, i32* %6, i32* null, i32* null, i32* null)
%16 = icmp sle i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %21)
br label %38
23: ; preds = %13
%24 = call i64 @FD_ISSET(i32 0, i32* %6)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i64 @copyData(i32 0, i32 6, i8* %11, i32 2048)
%28 = icmp ne i64 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %26, %23
%30 = call i64 @FD_ISSET(i32 7, i32* %6)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call i64 @copyData(i32 7, i32 1, i8* %11, i32 2048)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32, %26
br label %38
36: ; preds = %32, %29
br label %37
37: ; preds = %36
br label %12
38: ; preds = %35, %17
%39 = load i32, i32* @errno
store i32 %39, i32* %1
%40 = load i8*, i8** %5
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"fd-proxy: select failure errno=%d %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @FD_ZERO(i32* %1)
%5 = call i32 @FD_SET(i32 0, i32* %1)
%6 = call i32 @FD_SET(i32 7, i32* %1)
%7 = call i8* @llvm.stacksave()
%8 = alloca [2048 x i8]
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%10 = bitcast i32* %2 to i8*
%11 = load i32, i32* %1
store i32 %11, i32* %2
%12 = call i64 @select(i32 8, i32* %2, i32* null, i32* null, i32* null)
%13 = icmp slt i64 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %31, %0
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17)
br label %35
19: ; preds = %0, %31
%20 = call i64 @FD_ISSET(i32 0, i32* %2)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = call i64 @copyData(i32 0, i32 6, i8* %9, i32 2048)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22, %19
%26 = call i64 @FD_ISSET(i32 7, i32* %2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call i64 @copyData(i32 7, i32 1, i8* %9, i32 2048)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28, %25
%32 = load i32, i32* %1
store i32 %32, i32* %2
%33 = call i64 @select(i32 8, i32* %2, i32* null, i32* null, i32* null)
%34 = icmp slt i64 %33, 1
br i1 %34, label %14, label %19
35: ; preds = %28, %22, %14
%36 = load i32, i32* @errno
ret i32 %36
}