#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 size_t ssize_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int accept_conn(int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ clear_high_bit(char *, size_t);
int /*<<< orphan*/ close_conn(int *);
int /*<<< orphan*/ perror(char *);
size_t receive_data(int *, char *, int, int *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ set_high_bit(char *, size_t);
scalar_t__ write(int, char *, int);
void main_loop(int serial_fd, int low_listener, int high_listener) {
  fd_set rdfds;
  int low_poll = 0, high_poll = 0, serial_poll = 0;
  int low_fd = -1, high_fd = -1;
  while (1) {
    char buf[1024];
    ssize_t bytes;
    int max;
    FD_ZERO(&rdfds);
    FD_SET(low_fd < 0 ? low_listener : low_fd, &rdfds);
    FD_SET(high_fd < 0 ? high_listener : high_fd, &rdfds);
    FD_SET(serial_fd, &rdfds);
    max = ((low_fd) < (low_listener) ? (low_listener) : (low_fd));
    max = ((max) < (high_fd) ? (high_fd) : (max));
    max = ((max) < (high_listener) ? (high_listener) : (max));
    max = ((max) < (serial_fd) ? (serial_fd) : (max));
    if (select(max + 1, &rdfds, NULL, NULL, NULL) < 0) {
      perror("select");
      continue;
    }
    if (FD_ISSET(low_listener, &rdfds)) {
      assert(low_fd < 0);
      low_fd = accept_conn(low_listener);
    }
    if (FD_ISSET(high_listener, &rdfds)) {
      assert(high_fd < 0);
      high_fd = accept_conn(high_listener);
    }
    if (low_poll || (low_fd >= 0 && FD_ISSET(low_fd, &rdfds))) {
      if ((bytes = receive_data(&low_fd, &buf[0], sizeof(buf), &low_poll)) >
          0) {
        clear_high_bit(&buf[0], bytes);
        if (write(serial_fd, &buf[0], bytes) < 0)
          perror("write");
      }
    }
    if (high_poll || (high_fd >= 0 && FD_ISSET(high_fd, &rdfds))) {
      if ((bytes = receive_data(&high_fd, &buf[0], sizeof(buf), &high_poll)) >
          0) {
        set_high_bit(&buf[0], bytes);
        if (write(serial_fd, &buf[0], bytes) < 0)
          perror("write");
      }
    }
    if (serial_poll || FD_ISSET(serial_fd, &rdfds)) {
      if ((bytes = receive_data(&serial_fd, &buf[0], sizeof(buf),
                                &serial_poll)) > 0) {
        ssize_t i;
        for (i = 0; i < bytes; ++i) {
          if (buf[i] & 0x80) {
            if (high_fd >= 0) {
              buf[i] &= 0x7f;
              if ((write(high_fd, &buf[i], 1)) < 0) {
                perror("write");
                close_conn(&high_fd);
                high_poll = 0;
              }
            }
          } else {
            if (low_fd >= 0) {
              if ((write(low_fd, &buf[i], 1)) < 0) {
                perror("write");
                close_conn(&low_fd);
                low_poll = 0;
              }
            }
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    -0x10(%rbp),%rdi
call   1080 <FD_ZERO@plt>
cmpl   $0x0,-0x20(%rbp)
jge    1218 <main_loop+0x58>
mov    -0x8(%rbp),%eax
mov    %eax,-0x44c(%rbp)
jmp    1221 <main_loop+0x61>
mov    -0x20(%rbp),%eax
mov    %eax,-0x44c(%rbp)
mov    -0x44c(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10d0 <FD_SET@plt>
cmpl   $0x0,-0x24(%rbp)
jge    1248 <main_loop+0x88>
mov    -0xc(%rbp),%eax
mov    %eax,-0x450(%rbp)
jmp    1251 <main_loop+0x91>
mov    -0x24(%rbp),%eax
mov    %eax,-0x450(%rbp)
mov    -0x450(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1286 <main_loop+0xc6>
mov    -0x8(%rbp),%eax
mov    %eax,-0x454(%rbp)
jmp    128f <main_loop+0xcf>
mov    -0x20(%rbp),%eax
mov    %eax,-0x454(%rbp)
mov    -0x454(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x43c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12b8 <main_loop+0xf8>
mov    -0x24(%rbp),%eax
mov    %eax,-0x458(%rbp)
jmp    12c4 <main_loop+0x104>
mov    -0x43c(%rbp),%eax
mov    %eax,-0x458(%rbp)
mov    -0x458(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x43c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ed <main_loop+0x12d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x45c(%rbp)
jmp    12f9 <main_loop+0x139>
mov    -0x43c(%rbp),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x45c(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x43c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1322 <main_loop+0x162>
mov    -0x4(%rbp),%eax
mov    %eax,-0x460(%rbp)
jmp    132e <main_loop+0x16e>
mov    -0x43c(%rbp),%eax
mov    %eax,-0x460(%rbp)
mov    -0x460(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x43c(%rbp),%edi
add    $0x1,%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1090 <select@plt>
cmp    $0x0,%rax
jge    1372 <main_loop+0x1b2>
lea    0xc98(%rip),%rdi
call   10b0 <perror@plt>
jmp    11f7 <main_loop+0x37>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13a4 <main_loop+0x1e4>
cmpl   $0x0,-0x20(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%edi
call   10c0 <accept_conn@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13d6 <main_loop+0x216>
cmpl   $0x0,-0x24(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
call   10c0 <accept_conn@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1400 <main_loop+0x240>
cmpl   $0x0,-0x20(%rbp)
jl     1475 <main_loop+0x2b5>
mov    -0x20(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1475 <main_loop+0x2b5>
lea    -0x430(%rbp),%rsi
lea    -0x20(%rbp),%rdi
mov    $0x400,%edx
lea    -0x14(%rbp),%rcx
call   1040 <receive_data@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jbe    1470 <main_loop+0x2b0>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   10a0 <clear_high_bit@plt>
mov    -0x4(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x438(%rbp),%rax
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    146b <main_loop+0x2ab>
lea    0xba1(%rip),%rdi
call   10b0 <perror@plt>
jmp    1470 <main_loop+0x2b0>
jmp    1475 <main_loop+0x2b5>
cmpl   $0x0,-0x18(%rbp)
jne    149f <main_loop+0x2df>
cmpl   $0x0,-0x24(%rbp)
jl     1514 <main_loop+0x354>
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1514 <main_loop+0x354>
lea    -0x430(%rbp),%rsi
lea    -0x24(%rbp),%rdi
mov    $0x400,%edx
lea    -0x18(%rbp),%rcx
call   1040 <receive_data@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jbe    150f <main_loop+0x34f>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   10e0 <set_high_bit@plt>
mov    -0x4(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x438(%rbp),%rax
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    150a <main_loop+0x34a>
lea    0xb02(%rip),%rdi
call   10b0 <perror@plt>
jmp    150f <main_loop+0x34f>
jmp    1514 <main_loop+0x354>
cmpl   $0x0,-0x1c(%rbp)
jne    1534 <main_loop+0x374>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1683 <main_loop+0x4c3>
lea    -0x430(%rbp),%rsi
lea    -0x4(%rbp),%rdi
mov    $0x400,%edx
lea    -0x1c(%rbp),%rcx
call   1040 <receive_data@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jbe    167e <main_loop+0x4be>
movq   $0x0,-0x448(%rbp)
mov    -0x448(%rbp),%rax
cmp    -0x438(%rbp),%rax
jae    1679 <main_loop+0x4b9>
mov    -0x448(%rbp),%rax
movsbl -0x430(%rbp,%rax,1),%eax
ff
and    $0x80,%eax
cmp    $0x0,%eax
je     1608 <main_loop+0x448>
cmpl   $0x0,-0x24(%rbp)
jl     1603 <main_loop+0x443>
mov    -0x448(%rbp),%rax
movsbl -0x430(%rbp,%rax,1),%ecx
ff
and    $0x7f,%ecx
mov    %cl,-0x430(%rbp,%rax,1)
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
add    -0x448(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    15fe <main_loop+0x43e>
lea    0xa1e(%rip),%rdi
call   10b0 <perror@plt>
lea    -0x24(%rbp),%rdi
call   1030 <close_conn@plt>
movl   $0x0,-0x18(%rbp)
jmp    1603 <main_loop+0x443>
jmp    165d <main_loop+0x49d>
cmpl   $0x0,-0x20(%rbp)
jl     1658 <main_loop+0x498>
mov    -0x20(%rbp),%edi
lea    -0x430(%rbp),%rsi
add    -0x448(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    1653 <main_loop+0x493>
lea    0x9c9(%rip),%rdi
call   10b0 <perror@plt>
lea    -0x20(%rbp),%rdi
call   1030 <close_conn@plt>
movl   $0x0,-0x14(%rbp)
jmp    1658 <main_loop+0x498>
jmp    165d <main_loop+0x49d>
jmp    1662 <main_loop+0x4a2>
mov    -0x448(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x448(%rbp)
jmp    1569 <main_loop+0x3a9>
jmp    167e <main_loop+0x4be>
jmp    1683 <main_loop+0x4c3>
jmp    11f7 <main_loop+0x37>

x86 assembly (clang, -O2):
<main_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %edx,%r12d
mov    %esi,%ebp
mov    %edi,0xc(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0x4(%rsp)
ff
lea    0x1c(%rsp),%r14
lea    0xdf9(%rip),%rbx
jmp    121c <main_loop+0x5c>
lea    0xde9(%rip),%rdi
call   10b0 <perror@plt>
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
mov    0x8(%rsp),%edi
test   %edi,%edi
cmovs  %ebp,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
cmovs  %r12d,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0x8(%rsp),%edi
cmp    %ebp,%edi
cmovl  %ebp,%edi
mov    0x4(%rsp),%eax
cmp    %eax,%edi
cmovl  %eax,%edi
cmp    %r12d,%edi
cmovl  %r12d,%edi
mov    0xc(%rsp),%eax
cmp    %eax,%edi
cmovl  %eax,%edi
add    $0x1,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <select@plt>
test   %rax,%rax
js     1210 <main_loop+0x50>
mov    %rbx,%r13
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     12b5 <main_loop+0xf5>
mov    0x8(%rsp),%edi
shr    $0x1f,%edi
call   1070 <assert@plt>
mov    %ebp,%edi
call   10c0 <accept_conn@plt>
mov    %eax,0x8(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     12dd <main_loop+0x11d>
mov    0x4(%rsp),%edi
shr    $0x1f,%edi
call   1070 <assert@plt>
mov    %r12d,%edi
call   10c0 <accept_conn@plt>
mov    %eax,0x4(%rsp)
cmpl   $0x0,0x14(%rsp)
jne    1300 <main_loop+0x140>
mov    0x8(%rsp),%edi
test   %edi,%edi
js     1350 <main_loop+0x190>
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1350 <main_loop+0x190>
nopl   0x0(%rax)
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    $0x400,%edx
lea    0x14(%rsp),%rcx
call   1040 <receive_data@plt>
test   %rax,%rax
je     1350 <main_loop+0x190>
mov    %rax,%rbx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   10a0 <clear_high_bit@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    1350 <main_loop+0x190>
mov    %r13,%rdi
call   10b0 <perror@plt>
nopl   0x0(%rax)
cmpl   $0x0,0x10(%rsp)
jne    1370 <main_loop+0x1b0>
mov    0x4(%rsp),%edi
test   %edi,%edi
js     13c0 <main_loop+0x200>
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     13c0 <main_loop+0x200>
nopl   0x0(%rax)
lea    0x4(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    $0x400,%edx
lea    0x10(%rsp),%rcx
call   1040 <receive_data@plt>
test   %rax,%rax
je     13c0 <main_loop+0x200>
mov    %rax,%rbx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   10e0 <set_high_bit@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    13c0 <main_loop+0x200>
mov    %r13,%rdi
call   10b0 <perror@plt>
nopl   0x0(%rax)
cmpl   $0x0,0x18(%rsp)
mov    %r13,%rbx
jne    13df <main_loop+0x21f>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     121c <main_loop+0x5c>
lea    0xc(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    $0x400,%edx
lea    0x18(%rsp),%rcx
call   1040 <receive_data@plt>
test   %rax,%rax
je     121c <main_loop+0x5c>
mov    %rax,%r13
lea    0x20(%rsp),%r15
jmp    141e <main_loop+0x25e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0xffffffffffffffff,%r13
je     121c <main_loop+0x5c>
movzbl (%r15),%eax
test   %al,%al
js     1460 <main_loop+0x2a0>
mov    0x8(%rsp),%edi
test   %edi,%edi
js     1410 <main_loop+0x250>
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    1410 <main_loop+0x250>
mov    %rbx,%rdi
call   10b0 <perror@plt>
lea    0x8(%rsp),%rdi
call   1030 <close_conn@plt>
movl   $0x0,0x14(%rsp)
jmp    1410 <main_loop+0x250>
nopl   0x0(%rax)
mov    0x4(%rsp),%edi
test   %edi,%edi
js     1410 <main_loop+0x250>
and    $0x7f,%al
mov    %al,(%r15)
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    1410 <main_loop+0x250>
mov    %rbx,%rdi
call   10b0 <perror@plt>
lea    0x4(%rsp),%rdi
call   1030 <close_conn@plt>
movl   $0x0,0x10(%rsp)
jmp    1410 <main_loop+0x250>

LLVM IR (-O0):
@.str = [7 x i8] c"select\00"
@.str.1 = [6 x i8] c"write\00"
define void @main_loop(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca i64
%15 = alloca i32
%16 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 -1, i32* %11
store i32 -1, i32* %12
br label %17
17: ; preds = %3, %79, %222
%18 = call i32 @FD_ZERO(i32* %7)
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i32, i32* %5
br label %25
23: ; preds = %17
%24 = load i32, i32* %11
br label %25
25: ; preds = %23, %21
%26 = phi i32 [ %22, %21 ], [ %24, %23 ]
%27 = call i32 @FD_SET(i32 %26, i32* %7)
%28 = load i32, i32* %12
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i32, i32* %6
br label %34
32: ; preds = %25
%33 = load i32, i32* %12
br label %34
34: ; preds = %32, %30
%35 = phi i32 [ %31, %30 ], [ %33, %32 ]
%36 = call i32 @FD_SET(i32 %35, i32* %7)
%37 = load i32, i32* %4
%38 = call i32 @FD_SET(i32 %37, i32* %7)
%39 = load i32, i32* %11
%40 = load i32, i32* %5
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = load i32, i32* %5
br label %46
44: ; preds = %34
%45 = load i32, i32* %11
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
store i32 %47, i32* %15
%48 = load i32, i32* %15
%49 = load i32, i32* %12
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = load i32, i32* %12
br label %55
53: ; preds = %46
%54 = load i32, i32* %15
br label %55
55: ; preds = %53, %51
%56 = phi i32 [ %52, %51 ], [ %54, %53 ]
store i32 %56, i32* %15
%57 = load i32, i32* %15
%58 = load i32, i32* %6
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = load i32, i32* %6
br label %64
62: ; preds = %55
%63 = load i32, i32* %15
br label %64
64: ; preds = %62, %60
%65 = phi i32 [ %61, %60 ], [ %63, %62 ]
store i32 %65, i32* %15
%66 = load i32, i32* %15
%67 = load i32, i32* %4
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %71
69: ; preds = %64
%70 = load i32, i32* %4
br label %73
71: ; preds = %64
%72 = load i32, i32* %15
br label %73
73: ; preds = %71, %69
%74 = phi i32 [ %70, %69 ], [ %72, %71 ]
store i32 %74, i32* %15
%75 = load i32, i32* %15
%76 = add nsw i32 %75, 1
%77 = call i64 @select(i32 %76, i32* %7, i32* null, i32* null, i32* null)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %73
%80 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
81: ; preds = %73
%82 = load i32, i32* %5
%83 = call i64 @FD_ISSET(i32 %82, i32* %7)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %81
%86 = load i32, i32* %11
%87 = icmp slt i32 %86, 0
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = load i32, i32* %5
%91 = call i32 @accept_conn(i32 %90)
store i32 %91, i32* %11
br label %92
92: ; preds = %85, %81
%93 = load i32, i32* %6
%94 = call i64 @FD_ISSET(i32 %93, i32* %7)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %103
96: ; preds = %92
%97 = load i32, i32* %12
%98 = icmp slt i32 %97, 0
%99 = zext i1 %98 to i32
%100 = call i32 @assert(i32 %99)
%101 = load i32, i32* %6
%102 = call i32 @accept_conn(i32 %101)
store i32 %102, i32* %12
br label %103
103: ; preds = %96, %92
%104 = load i32, i32* %8
%105 = icmp ne i32 %104, 0
br i1 %105, label %113, label %106
106: ; preds = %103
%107 = load i32, i32* %11
%108 = icmp sge i32 %107, 0
br i1 %108, label %109, label %131
109: ; preds = %106
%110 = load i32, i32* %11
%111 = call i64 @FD_ISSET(i32 %110, i32* %7)
%112 = icmp ne i64 %111, 0
br i1 %112, label %113, label %131
113: ; preds = %109, %103
%114 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%115 = call i64 @receive_data(i32* %11, i8* %114, i32 1024, i32* %8)
store i64 %115, i64* %14
%116 = icmp ugt i64 %115, 0
br i1 %116, label %117, label %130
117: ; preds = %113
%118 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%119 = load i64, i64* %14
%120 = call i32 @clear_high_bit(i8* %118, i64 %119)
%121 = load i32, i32* %4
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%123 = load i64, i64* %14
%124 = trunc i64 %123 to i32
%125 = call i64 @write(i32 %121, i8* %122, i32 %124)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %117
%128 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %129
129: ; preds = %127, %117
br label %130
130: ; preds = %129, %113
br label %131
131: ; preds = %130, %109, %106
%132 = load i32, i32* %9
%133 = icmp ne i32 %132, 0
br i1 %133, label %141, label %134
134: ; preds = %131
%135 = load i32, i32* %12
%136 = icmp sge i32 %135, 0
br i1 %136, label %137, label %159
137: ; preds = %134
%138 = load i32, i32* %12
%139 = call i64 @FD_ISSET(i32 %138, i32* %7)
%140 = icmp ne i64 %139, 0
br i1 %140, label %141, label %159
141: ; preds = %137, %131
%142 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%143 = call i64 @receive_data(i32* %12, i8* %142, i32 1024, i32* %9)
store i64 %143, i64* %14
%144 = icmp ugt i64 %143, 0
br i1 %144, label %145, label %158
145: ; preds = %141
%146 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%147 = load i64, i64* %14
%148 = call i32 @set_high_bit(i8* %146, i64 %147)
%149 = load i32, i32* %4
%150 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%151 = load i64, i64* %14
%152 = trunc i64 %151 to i32
%153 = call i64 @write(i32 %149, i8* %150, i32 %152)
%154 = icmp slt i64 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %145
%156 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %157
157: ; preds = %155, %145
br label %158
158: ; preds = %157, %141
br label %159
159: ; preds = %158, %137, %134
%160 = load i32, i32* %10
%161 = icmp ne i32 %160, 0
br i1 %161, label %166, label %162
162: ; preds = %159
%163 = load i32, i32* %4
%164 = call i64 @FD_ISSET(i32 %163, i32* %7)
%165 = icmp ne i64 %164, 0
br i1 %165, label %166, label %222
166: ; preds = %162, %159
%167 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%168 = call i64 @receive_data(i32* %4, i8* %167, i32 1024, i32* %10)
store i64 %168, i64* %14
%169 = icmp ugt i64 %168, 0
br i1 %169, label %170, label %221
170: ; preds = %166
store i64 0, i64* %16
br label %171
171: ; preds = %217, %170
%172 = load i64, i64* %16
%173 = load i64, i64* %14
%174 = icmp ult i64 %172, %173
br i1 %174, label %175, label %220
175: ; preds = %171
%176 = load i64, i64* %16
%177 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %176
%178 = load i8, i8* %177
%179 = sext i8 %178 to i32
%180 = and i32 %179, 128
%181 = icmp ne i32 %180, 0
br i1 %181, label %182, label %202
182: ; preds = %175
%183 = load i32, i32* %12
%184 = icmp sge i32 %183, 0
br i1 %184, label %185, label %201
185: ; preds = %182
%186 = load i64, i64* %16
%187 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %186
%188 = load i8, i8* %187
%189 = sext i8 %188 to i32
%190 = and i32 %189, 127
%191 = trunc i32 %190 to i8
store i8 %191, i8* %187
%192 = load i32, i32* %12
%193 = load i64, i64* %16
%194 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %193
%195 = call i64 @write(i32 %192, i8* %194, i32 1)
%196 = icmp slt i64 %195, 0
br i1 %196, label %197, label %200
197: ; preds = %185
%198 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%199 = call i32 @close_conn(i32* %12)
store i32 0, i32* %9
br label %200
200: ; preds = %197, %185
br label %201
201: ; preds = %200, %182
br label %216
202: ; preds = %175
%203 = load i32, i32* %11
%204 = icmp sge i32 %203, 0
br i1 %204, label %205, label %215
205: ; preds = %202
%206 = load i32, i32* %11
%207 = load i64, i64* %16
%208 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %207
%209 = call i64 @write(i32 %206, i8* %208, i32 1)
%210 = icmp slt i64 %209, 0
br i1 %210, label %211, label %214
211: ; preds = %205
%212 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%213 = call i32 @close_conn(i32* %11)
store i32 0, i32* %8
br label %214
214: ; preds = %211, %205
br label %215
215: ; preds = %214, %202
br label %216
216: ; preds = %215, %201
br label %217
217: ; preds = %216
%218 = load i64, i64* %16
%219 = add i64 %218, 1
store i64 %219, i64* %16
br label %171
220: ; preds = %171
br label %221
221: ; preds = %220, %166
br label %222
222: ; preds = %221, %162
br label %17
}

LLVM IR (-O2):
@.str = [7 x i8] c"select\00"
@.str.1 = [6 x i8] c"write\00"
define void @main_loop(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
store i32 %0, i32* %4
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%14 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%15 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%16 = bitcast i32* %9 to i8*
store i32 -1, i32* %9
%17 = bitcast i32* %10 to i8*
store i32 -1, i32* %10
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
br label %19
19: ; preds = %140, %3
%20 = call i32 @FD_ZERO(i32* %5)
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
%23 = select i1 %22, i32 %1, i32 %21
%24 = call i32 @FD_SET(i32 %23, i32* %5)
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 0
%27 = select i1 %26, i32 %2, i32 %25
%28 = call i32 @FD_SET(i32 %27, i32* %5)
%29 = load i32, i32* %4
%30 = call i32 @FD_SET(i32 %29, i32* %5)
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, %1
%33 = select i1 %32, i32 %1, i32 %31
%34 = load i32, i32* %10
%35 = icmp slt i32 %33, %34
%36 = select i1 %35, i32 %34, i32 %33
%37 = icmp slt i32 %36, %2
%38 = select i1 %37, i32 %2, i32 %36
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
%41 = select i1 %40, i32 %39, i32 %38
%42 = add nsw i32 %41, 1
%43 = call i64 @select(i32 %42, i32* %5, i32* null, i32* null, i32* null)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %19
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %140
47: ; preds = %19
%48 = call i64 @FD_ISSET(i32 %1, i32* %5)
%49 = icmp eq i64 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %47
%51 = load i32, i32* %9
%52 = lshr i32 %51, 31
%53 = call i32 @assert(i32 %52)
%54 = call i32 @accept_conn(i32 %1)
store i32 %54, i32* %9
br label %55
55: ; preds = %50, %47
%56 = call i64 @FD_ISSET(i32 %2, i32* %5)
%57 = icmp eq i64 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %55
%59 = load i32, i32* %10
%60 = lshr i32 %59, 31
%61 = call i32 @assert(i32 %60)
%62 = call i32 @accept_conn(i32 %2)
store i32 %62, i32* %10
br label %63
63: ; preds = %58, %55
%64 = load i32, i32* %6
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %63
%67 = load i32, i32* %9
%68 = icmp sgt i32 %67, -1
br i1 %68, label %69, label %83
69: ; preds = %66
%70 = call i64 @FD_ISSET(i32 %67, i32* %5)
%71 = icmp eq i64 %70, 0
br i1 %71, label %83, label %72
72: ; preds = %69, %63
%73 = call i64 @receive_data(i32* %9, i8* %18, i32 1024, i32* %6)
%74 = icmp eq i64 %73, 0
br i1 %74, label %83, label %75
75: ; preds = %72
%76 = call i32 @clear_high_bit(i8* %18, i64 %73)
%77 = load i32, i32* %4
%78 = trunc i64 %73 to i32
%79 = call i64 @write(i32 %77, i8* %18, i32 %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %75
%82 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %83
83: ; preds = %72, %81, %75, %69, %66
%84 = load i32, i32* %7
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %92
86: ; preds = %83
%87 = load i32, i32* %10
%88 = icmp sgt i32 %87, -1
br i1 %88, label %89, label %103
89: ; preds = %86
%90 = call i64 @FD_ISSET(i32 %87, i32* %5)
%91 = icmp eq i64 %90, 0
br i1 %91, label %103, label %92
92: ; preds = %89, %83
%93 = call i64 @receive_data(i32* %10, i8* %18, i32 1024, i32* %7)
%94 = icmp eq i64 %93, 0
br i1 %94, label %103, label %95
95: ; preds = %92
%96 = call i32 @set_high_bit(i8* %18, i64 %93)
%97 = load i32, i32* %4
%98 = trunc i64 %93 to i32
%99 = call i64 @write(i32 %97, i8* %18, i32 %98)
%100 = icmp slt i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %95
%102 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %103
103: ; preds = %92, %101, %95, %89, %86
%104 = load i32, i32* %8
%105 = icmp eq i32 %104, 0
br i1 %105, label %106, label %110
106: ; preds = %103
%107 = load i32, i32* %4
%108 = call i64 @FD_ISSET(i32 %107, i32* %5)
%109 = icmp eq i64 %108, 0
br i1 %109, label %140, label %110
110: ; preds = %106, %103
%111 = call i64 @receive_data(i32* %4, i8* %18, i32 1024, i32* %8)
%112 = icmp eq i64 %111, 0
br i1 %112, label %140, label %113
113: ; preds = %110, %137
%114 = phi i64 [ %138, %137 ], [ 0, %110 ]
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %114
%116 = load i8, i8* %115
%117 = icmp sgt i8 %116, -1
br i1 %117, label %128, label %118
118: ; preds = %113
%119 = load i32, i32* %10
%120 = icmp sgt i32 %119, -1
br i1 %120, label %121, label %137
121: ; preds = %118
%122 = and i8 %116, 127
store i8 %122, i8* %115
%123 = call i64 @write(i32 %119, i8* %115, i32 1)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %137
125: ; preds = %121
%126 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%127 = call i32 @close_conn(i32* %10)
store i32 0, i32* %7
br label %137
128: ; preds = %113
%129 = load i32, i32* %9
%130 = icmp sgt i32 %129, -1
br i1 %130, label %131, label %137
131: ; preds = %128
%132 = call i64 @write(i32 %129, i8* %115, i32 1)
%133 = icmp slt i64 %132, 0
br i1 %133, label %134, label %137
134: ; preds = %131
%135 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%136 = call i32 @close_conn(i32* %9)
store i32 0, i32* %6
br label %137
137: ; preds = %121, %125, %118, %131, %134, %128
%138 = add nuw i64 %114, 1
%139 = icmp eq i64 %138, %111
br i1 %139, label %140, label %113
140: ; preds = %137, %106, %110, %45
br label %19
}