#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*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pthread_exit(void *);
int read(int, void *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int writen(int, void *, int);
void local_tunnel(int sock1, int sock2) {
  fprintf(stderr, "Tunneling between fd=%d and fd=%d\n", sock1, sock2);
  while (1) {
    int size_in, size_out, in, out, maxfd, err;
    char buf[4096], *dir;
    fd_set readfds, exceptfds;
    FD_ZERO(&readfds);
    FD_ZERO(&exceptfds);
    FD_SET(sock1, &readfds);
    FD_SET(sock2, &readfds);
    FD_SET(sock1, &exceptfds);
    FD_SET(sock2, &exceptfds);
    maxfd = sock1;
    if (sock2 > maxfd)
      maxfd = sock2;
    maxfd++;
    err = select(maxfd, &readfds, NULL, &exceptfds, NULL);
    if (err < 0) {
      perror("select");
      close(sock1);
      close(sock2);
      pthread_exit((void *)-1);
    }
    if (FD_ISSET(sock1, &exceptfds) || FD_ISSET(sock2, &exceptfds)) {
      fprintf(stderr, "(launcher-tunnel) select() reported exceptions!\n");
      close(sock1);
      close(sock2);
      pthread_exit((void *)-1);
    }
    if (FD_ISSET(sock1, &readfds)) {
      in = sock1;
      out = sock2;
      dir = "out";
    } else if (FD_ISSET(sock2, &readfds)) {
      in = sock2;
      out = sock1;
      dir = "in";
    } else {
      fprintf(stderr, "(launcher-tunnel) select() succeeded, but no file "
                      "descriptors are ready to be read!\n");
      close(sock1);
      close(sock2);
      pthread_exit((void *)-1);
    }
    size_in = read(in, (void *)buf, 4096);
    if (size_in < 0) {
      perror("read");
      continue;
    } else if (size_in == 0) {
      fprintf(stderr,
              "(launcher-tunnel) A connection (%d) was closed "
              "(EOF on read).\n",
              in);
      close(sock1);
      close(sock2);
      pthread_exit((void *)0);
    }
    size_out = writen(out, (void *)buf, size_in);
    if (size_out < 0) {
      perror("write");
      fprintf(stderr,
              "(launcher-tunnel) A connection (%d) was closed "
              "(EOF on write).\n",
              out);
      close(sock1);
      close(sock2);
      pthread_exit((void *)0);
    }
    if (size_in != size_out) {
      fprintf(stderr,
              "(launcher-tunnel) Somehow lost bytes, "
              "from %d in to %d out!\n",
              size_in, size_out);
      continue;
    }
  }
  pthread_exit((void *)0);
}


x86 assembly (clang, -O0):
<local_tunnel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x102c(%rbp),%rdi
call   1070 <FD_ZERO@plt>
lea    -0x1030(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x102c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x102c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x4(%rbp),%edi
lea    -0x1030(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x1030(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    123a <local_tunnel+0x9a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x102c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x1030(%rbp),%rcx
mov    %r8,%rdx
call   1080 <select@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1296 <local_tunnel+0xf6>
lea    0xdae(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    $0xffffffffffffffff,%rdi
call   1090 <pthread_exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x1030(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
jne    12c8 <local_tunnel+0x128>
mov    -0x8(%rbp),%edi
lea    -0x1030(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12fb <local_tunnel+0x15b>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    $0xffffffffffffffff,%rdi
call   1090 <pthread_exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x102c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1333 <local_tunnel+0x193>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xd34(%rip),%rax
mov    %rax,-0x1028(%rbp)
jmp    13a3 <local_tunnel+0x203>
mov    -0x8(%rbp),%edi
lea    -0x102c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     136b <local_tunnel+0x1cb>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xd00(%rip),%rax
mov    %rax,-0x1028(%rbp)
jmp    139e <local_tunnel+0x1fe>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    $0xffffffffffffffff,%rdi
call   1090 <pthread_exit@plt>
jmp    13a3 <local_tunnel+0x203>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    13d5 <local_tunnel+0x235>
lea    0xcec(%rip),%rdi
call   10a0 <perror@plt>
jmp    11ce <local_tunnel+0x2e>
cmpl   $0x0,-0xc(%rbp)
jne    1412 <local_tunnel+0x272>
mov    0x2bfa(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <pthread_exit@plt>
jmp    1417 <local_tunnel+0x277>
mov    -0x18(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10b0 <writen@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1475 <local_tunnel+0x2d5>
lea    0xcbe(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xcac(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <pthread_exit@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     14a3 <local_tunnel+0x303>
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xcaa(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11ce <local_tunnel+0x2e>
jmp    11ce <local_tunnel+0x2e>

x86 assembly (clang, -O2):
<local_tunnel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %esi,%r13d
mov    %edi,%r14d
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    %r14d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    %r14d,%r13d
mov    %r14d,%eax
cmovg  %r13d,%eax
add    $0x1,%eax
mov    %eax,0x8(%rsp)
lea    0xc(%rsp),%rbp
jmp    1207 <local_tunnel+0x67>
nopl   0x0(%rax)
lea    0xeb9(%rip),%rdi
call   10a0 <perror@plt>
mov    %ebx,%r15d
mov    %ebp,%r12d
lea    0xc(%rsp),%rbp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %rbp,%rdi
call   1070 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   1080 <select@plt>
test   %eax,%eax
jns    1288 <local_tunnel+0xe8>
lea    0xdbc(%rip),%rdi
call   10a0 <perror@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
mov    $0xffffffffffffffff,%rdi
call   1090 <pthread_exit@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    12a8 <local_tunnel+0x108>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12db <local_tunnel+0x13b>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
mov    $0xffffffffffffffff,%rdi
call   1090 <pthread_exit@plt>
mov    %r14d,%edi
lea    0x4(%rsp),%rsi
call   1030 <FD_ISSET@plt>
mov    %r13d,%ebx
mov    %r14d,%ebp
test   %rax,%rax
jne    1344 <local_tunnel+0x1a4>
mov    %r13d,%edi
lea    0x4(%rsp),%rsi
call   1030 <FD_ISSET@plt>
mov    %r14d,%ebx
mov    %r13d,%ebp
test   %rax,%rax
jne    1344 <local_tunnel+0x1a4>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
mov    $0xffffffffffffffff,%rdi
call   1090 <pthread_exit@plt>
mov    %r15d,%ebx
mov    %r12d,%ebp
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11f0 <local_tunnel+0x50>
mov    %eax,%r15d
jne    1392 <local_tunnel+0x1f2>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
mov    %r15d,%edx
call   10b0 <writen@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    13e4 <local_tunnel+0x244>
lea    0xd45(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
cmp    %r12d,%r15d
je     11fc <local_tunnel+0x5c>
mov    0x2bec(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11fc <local_tunnel+0x5c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Tunneling between fd=%d and fd=%d\0A\00"
@.str.1 = [7 x i8] c"select\00"
@.str.2 = [49 x i8] c"(launcher-tunnel) select() reported exceptions!\0A\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [3 x i8] c"in\00"
@.str.5 = [85 x i8] c"(launcher-tunnel) select() succeeded, but no file descriptors are ready to be read!\0A\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [63 x i8] c"(launcher-tunnel) A connection (%d) was closed (EOF on read).\0A\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [64 x i8] c"(launcher-tunnel) A connection (%d) was closed (EOF on write).\0A\00"
@.str.10 = [61 x i8] c"(launcher-tunnel) Somehow lost bytes, from %d in to %d out!\0A\00"
define void @local_tunnel(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4096 x i8]
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%15 = load i32, i32* @stderr
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
br label %19
19: ; preds = %2, %95, %131, %136
%20 = call i32 @FD_ZERO(i32* %13)
%21 = call i32 @FD_ZERO(i32* %14)
%22 = load i32, i32* %3
%23 = call i32 @FD_SET(i32 %22, i32* %13)
%24 = load i32, i32* %4
%25 = call i32 @FD_SET(i32 %24, i32* %13)
%26 = load i32, i32* %3
%27 = call i32 @FD_SET(i32 %26, i32* %14)
%28 = load i32, i32* %4
%29 = call i32 @FD_SET(i32 %28, i32* %14)
%30 = load i32, i32* %3
store i32 %30, i32* %9
%31 = load i32, i32* %4
%32 = load i32, i32* %9
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %19
%35 = load i32, i32* %4
store i32 %35, i32* %9
br label %36
36: ; preds = %34, %19
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = call i32 @select(i32 %39, i32* %13, i32* null, i32* %14, i32* null)
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %36
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* %3
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* %4
%48 = call i32 @close(i32 %47)
%49 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %50
50: ; preds = %43, %36
%51 = load i32, i32* %3
%52 = call i64 @FD_ISSET(i32 %51, i32* %14)
%53 = icmp ne i64 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = load i32, i32* %4
%56 = call i64 @FD_ISSET(i32 %55, i32* %14)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %54, %50
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* %3
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* %4
%64 = call i32 @close(i32 %63)
%65 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %66
66: ; preds = %58, %54
%67 = load i32, i32* %3
%68 = call i64 @FD_ISSET(i32 %67, i32* %13)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = load i32, i32* %3
store i32 %71, i32* %7
%72 = load i32, i32* %4
store i32 %72, i32* %8
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %12
br label %89
73: ; preds = %66
%74 = load i32, i32* %4
%75 = call i64 @FD_ISSET(i32 %74, i32* %13)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %73
%78 = load i32, i32* %4
store i32 %78, i32* %7
%79 = load i32, i32* %3
store i32 %79, i32* %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %12
br label %88
80: ; preds = %73
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32, i32* %3
%84 = call i32 @close(i32 %83)
%85 = load i32, i32* %4
%86 = call i32 @close(i32 %85)
%87 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %88
88: ; preds = %80, %77
br label %89
89: ; preds = %88, %70
%90 = load i32, i32* %7
%91 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%92 = call i32 @read(i32 %90, i8* %91, i32 4096)
store i32 %92, i32* %5
%93 = load i32, i32* %5
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %89
%96 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %19
97: ; preds = %89
%98 = load i32, i32* %5
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %109
100: ; preds = %97
%101 = load i32, i32* @stderr
%102 = load i32, i32* %7
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.7, i64 0, i64 0), i32 %102)
%104 = load i32, i32* %3
%105 = call i32 @close(i32 %104)
%106 = load i32, i32* %4
%107 = call i32 @close(i32 %106)
%108 = call i32 @pthread_exit(i8* null)
br label %109
109: ; preds = %100, %97
br label %110
110: ; preds = %109
%111 = load i32, i32* %8
%112 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%113 = load i32, i32* %5
%114 = call i32 @writen(i32 %111, i8* %112, i32 %113)
store i32 %114, i32* %6
%115 = load i32, i32* %6
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %127
117: ; preds = %110
%118 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%119 = load i32, i32* @stderr
%120 = load i32, i32* %8
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i32 %120)
%122 = load i32, i32* %3
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* %4
%125 = call i32 @close(i32 %124)
%126 = call i32 @pthread_exit(i8* null)
br label %127
127: ; preds = %117, %110
%128 = load i32, i32* %5
%129 = load i32, i32* %6
%130 = icmp ne i32 %128, %129
br i1 %130, label %131, label %136
131: ; preds = %127
%132 = load i32, i32* @stderr
%133 = load i32, i32* %5
%134 = load i32, i32* %6
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.10, i64 0, i64 0), i32 %133, i32 %134)
br label %19
136: ; preds = %127
br label %19
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Tunneling between fd=%d and fd=%d\0A\00"
@.str.1 = [7 x i8] c"select\00"
@.str.2 = [49 x i8] c"(launcher-tunnel) select() reported exceptions!\0A\00"
@.str.5 = [85 x i8] c"(launcher-tunnel) select() succeeded, but no file descriptors are ready to be read!\0A\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [63 x i8] c"(launcher-tunnel) A connection (%d) was closed (EOF on read).\0A\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [64 x i8] c"(launcher-tunnel) A connection (%d) was closed (EOF on write).\0A\00"
@.str.10 = [61 x i8] c"(launcher-tunnel) Somehow lost bytes, from %d in to %d out!\0A\00"
define void @local_tunnel(i32 %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = icmp sgt i32 %1, %0
%12 = select i1 %11, i32 %1, i32 %0
%13 = add nsw i32 %12, 1
br label %14
14: ; preds = %84, %2
%15 = phi i32 [ undef, %2 ], [ %55, %84 ]
%16 = phi i32 [ undef, %2 ], [ %56, %84 ]
%17 = call i32 @FD_ZERO(i32* %4)
%18 = call i32 @FD_ZERO(i32* %5)
%19 = call i32 @FD_SET(i32 %0, i32* %4)
%20 = call i32 @FD_SET(i32 %1, i32* %4)
%21 = call i32 @FD_SET(i32 %0, i32* %5)
%22 = call i32 @FD_SET(i32 %1, i32* %5)
%23 = call i32 @select(i32 %13, i32* %4, i32* null, i32* %5, i32* null)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @close(i32 %0)
%28 = call i32 @close(i32 %1)
%29 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %30
30: ; preds = %25, %14
%31 = call i64 @FD_ISSET(i32 %0, i32* %5)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i64 @FD_ISSET(i32 %1, i32* %5)
%35 = icmp eq i64 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %33, %30
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @close(i32 %0)
%40 = call i32 @close(i32 %1)
%41 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %42
42: ; preds = %36, %33
%43 = call i64 @FD_ISSET(i32 %0, i32* %4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = call i64 @FD_ISSET(i32 %1, i32* %4)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @close(i32 %0)
%52 = call i32 @close(i32 %1)
%53 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %54
54: ; preds = %45, %42, %48
%55 = phi i32 [ %15, %48 ], [ %1, %42 ], [ %0, %45 ]
%56 = phi i32 [ %16, %48 ], [ %0, %42 ], [ %1, %45 ]
%57 = call i32 @read(i32 %56, i8* %8, i32 4096)
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %84
61: ; preds = %54
%62 = icmp eq i32 %57, 0
br i1 %62, label %63, label %69
63: ; preds = %61
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.7, i64 0, i64 0), i32 %56)
%66 = call i32 @close(i32 %0)
%67 = call i32 @close(i32 %1)
%68 = call i32 @pthread_exit(i8* null)
br label %69
69: ; preds = %61, %63
%70 = call i32 @writen(i32 %55, i8* %8, i32 %57)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %69
%73 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i32 %55)
%76 = call i32 @close(i32 %0)
%77 = call i32 @close(i32 %1)
%78 = call i32 @pthread_exit(i8* null)
br label %79
79: ; preds = %72, %69
%80 = icmp eq i32 %57, %70
br i1 %80, label %84, label %81
81: ; preds = %79
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.10, i64 0, i64 0), i32 %57, i32 %70)
br label %84
84: ; preds = %79, %81, %59
br label %14
}