#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*/ *);
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ copy_data(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int input_fd = open("/tmp/blastem_input", O_WRONLY);
  int output_fd = open("/tmp/blastem_output", O_RDONLY);
  fd_set read_fds;
  FD_ZERO(&read_fds);
  for (;;) {
    FD_SET(STDIN_FILENO, &read_fds);
    FD_SET(output_fd, &read_fds);
    select(output_fd + 1, &read_fds, NULL, NULL, NULL);
    if (FD_ISSET(STDIN_FILENO, &read_fds)) {
      copy_data(input_fd, STDIN_FILENO);
    }
    if (FD_ISSET(output_fd, &read_fds)) {
      copy_data(STDOUT_FILENO, output_fd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
call   1080 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1080 <FD_SET@plt>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <select@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1214 <main+0xb4>
mov    -0x14(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
call   1060 <copy_data@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     123b <main+0xdb>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
call   1060 <copy_data@plt>
jmp    11af <main+0x4f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebp,%r15d
add    $0x1,%r15d
mov    0x2e1b(%rip),%r12
mov    0x2e34(%rip),%r13
nopl   0x0(%rax)
mov    (%r12),%edi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <select@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1205 <main+0xa5>
mov    (%r12),%esi
mov    %r14d,%edi
call   1060 <copy_data@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    0x0(%r13),%edi
mov    %ebp,%esi
call   1060 <copy_data@plt>
jmp    11c0 <main+0x60>

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/blastem_input\00"
@O_WRONLY = global i32 0
@.str.1 = [20 x i8] c"/tmp/blastem_output\00"
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 %12, i32* %7
%13 = call i32 @FD_ZERO(i32* %8)
br label %14
14: ; preds = %37, %2
%15 = load i32, i32* @STDIN_FILENO
%16 = call i32 @FD_SET(i32 %15, i32* %8)
%17 = load i32, i32* %7
%18 = call i32 @FD_SET(i32 %17, i32* %8)
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
%21 = call i32 @select(i32 %20, i32* %8, i32* null, i32* null, i32* null)
%22 = load i32, i32* @STDIN_FILENO
%23 = call i64 @FD_ISSET(i32 %22, i32* %8)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %14
%26 = load i32, i32* %6
%27 = load i32, i32* @STDIN_FILENO
%28 = call i32 @copy_data(i32 %26, i32 %27)
br label %29
29: ; preds = %25, %14
%30 = load i32, i32* %7
%31 = call i64 @FD_ISSET(i32 %30, i32* %8)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @STDOUT_FILENO
%35 = load i32, i32* %7
%36 = call i32 @copy_data(i32 %34, i32 %35)
br label %37
37: ; preds = %33, %29
br label %14
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/blastem_input\00"
@O_WRONLY = global i32 0
@.str.1 = [20 x i8] c"/tmp/blastem_output\00"
@O_RDONLY = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = bitcast i32* %3 to i8*
%9 = call i32 @FD_ZERO(i32* %3)
%10 = add nsw i32 %7, 1
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @FD_SET(i32 %12, i32* %3)
%14 = call i32 @FD_SET(i32 %7, i32* %3)
%15 = call i32 @select(i32 %10, i32* %3, i32* null, i32* null, i32* null)
%16 = load i32, i32* @STDIN_FILENO
%17 = call i64 @FD_ISSET(i32 %16, i32* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @copy_data(i32 %5, i32 %20)
br label %22
22: ; preds = %19, %11
%23 = call i64 @FD_ISSET(i32 %7, i32* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i32 @copy_data(i32 %26, i32 %7)
br label %28
28: ; preds = %25, %22
br label %11
}