#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*/ uint8_t;
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ _demultiplex_slip(int /*<<< orphan*/ *, int, int);
scalar_t__ _write_char(int, int);
int /*<<< orphan*/ _write_escaped(int, int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ isatty(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, int /*<<< orphan*/ *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int _dispatch(int iface_fd, int stream_fd, int in_fd, int out_fd) {
  static uint8_t buffer[(1500U)];
  fd_set readfds;
  int max_fd = (iface_fd > stream_fd)
                   ? ((iface_fd > in_fd) ? iface_fd : in_fd)
                   : ((stream_fd > in_fd) ? stream_fd : in_fd);
  int input_open = 1;
  int ret = 0;
  FILE *stream = fdopen(stream_fd, "r");
  fprintf(stderr, "Starting dispatch. TUN: %d, Stream: %d, In: %d, Out: %d\n",
          iface_fd, stream_fd, in_fd, out_fd);
  while (1) {
    int res;
    FD_ZERO(&readfds);
    FD_SET(iface_fd, &readfds);
    FD_SET(stream_fd, &readfds);
    if (input_open) {
      FD_SET(in_fd, &readfds);
    }
    res = select(max_fd + 1, &readfds, NULL, NULL, NULL);
    if ((res < 0) && (errno != EINTR)) {
      perror("select");
    }
    if (FD_ISSET(stream_fd, &readfds)) {
      if (_demultiplex_slip(stream, iface_fd, out_fd) < 0) {
        fputs("Connection lost to serial.\n", stderr);
        ret = -1;
        close(stream_fd);
        break;
      }
    }
    if (FD_ISSET(iface_fd, &readfds)) {
      ssize_t res = read(iface_fd, buffer, sizeof(buffer));
      if (res <= 0) {
        perror("Error reading TUN interface");
        continue;
      }
      _write_escaped(stream_fd, buffer, res);
    }
    if (FD_ISSET(in_fd, &readfds)) {
      ssize_t res = read(in_fd, buffer, sizeof(buffer));
      if (res == 0) {
        fputs("EOF from input\n", stderr);
        if (isatty(in_fd)) {
          fputs("Exit by user.\n", stderr);
          break;
        } else {
          close(in_fd);
          input_open = 0;
        }
        continue;
      }
      if (res < 0) {
        perror("Error reading from input");
        continue;
      }
      if (_write_char(stream_fd, 0x0aU) < 0) {
        continue;
      }
      _write_escaped(stream_fd, buffer, res);
    }
  }
  fclose(stream);
  return ret;
}


x86 assembly (clang, -O0):
<_dispatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1238 <_dispatch+0x48>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1227 <_dispatch+0x37>
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    122d <_dispatch+0x3d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    125b <_dispatch+0x6b>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    124f <_dispatch+0x5f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    1255 <_dispatch+0x65>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    0xd87(%rip),%rsi
call   10e0 <fdopen@plt>
mov    %rax,-0x28(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0xd62(%rip),%rsi
call   10b0 <fprintf@plt>
lea    -0x14(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1110 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1110 <FD_SET@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12dc <_dispatch+0xec>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1110 <FD_SET@plt>
mov    -0x18(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10d0 <select@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1329 <_dispatch+0x139>
mov    0x2cce(%rip),%rax
mov    (%rax),%rax
mov    0x2cbc(%rip),%rcx
cmp    (%rcx),%rax
je     1329 <_dispatch+0x139>
lea    0xd17(%rip),%rdi
call   1100 <perror@plt>
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1386 <_dispatch+0x196>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <_demultiplex_slip@plt>
cmp    $0x0,%rax
jge    1381 <_dispatch+0x191>
mov    0x2c81(%rip),%rax
mov    (%rax),%esi
lea    0xcda(%rip),%rdi
call   1070 <fputs@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
jmp    14c1 <_dispatch+0x2d1>
jmp    1386 <_dispatch+0x196>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13e3 <_dispatch+0x1f3>
mov    -0x4(%rbp),%edi
lea    0x2d0a(%rip),%rsi
mov    $0x1770,%edx
call   10a0 <read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jg     13d0 <_dispatch+0x1e0>
lea    0xc98(%rip),%rdi
call   1100 <perror@plt>
jmp    12a5 <_dispatch+0xb5>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rdx
lea    0x2cd2(%rip),%rsi
call   1090 <_write_escaped@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14bc <_dispatch+0x2cc>
mov    -0xc(%rbp),%edi
lea    0x2cad(%rip),%rsi
mov    $0x1770,%edx
call   10a0 <read@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1471 <_dispatch+0x281>
mov    0x2bbd(%rip),%rax
mov    (%rax),%esi
lea    0xc4e(%rip),%rdi
call   1070 <fputs@plt>
mov    -0xc(%rbp),%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     145d <_dispatch+0x26d>
mov    0x2b96(%rip),%rax
mov    (%rax),%esi
lea    0xc37(%rip),%rdi
call   1070 <fputs@plt>
jmp    14c1 <_dispatch+0x2d1>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x1c(%rbp)
jmp    12a5 <_dispatch+0xb5>
cmpq   $0x0,-0x40(%rbp)
jge    148d <_dispatch+0x29d>
lea    0xc16(%rip),%rdi
call   1100 <perror@plt>
jmp    12a5 <_dispatch+0xb5>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10f0 <_write_char@plt>
cmp    $0x0,%rax
jge    14a9 <_dispatch+0x2b9>
jmp    12a5 <_dispatch+0xb5>
mov    -0x8(%rbp),%edi
mov    -0x40(%rbp),%rdx
lea    0x2bf9(%rip),%rsi
call   1090 <_write_escaped@plt>
jmp    12a5 <_dispatch+0xb5>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dispatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %edi,%ebx
cmp    %edx,%edi
mov    %edx,%r14d
cmovg  %edi,%r14d
mov    %ecx,%r12d
mov    %esi,%ebp
cmp    %esi,%r14d
cmovle %esi,%r14d
lea    0xde1(%rip),%rsi
mov    %ebp,%edi
call   10e0 <fdopen@plt>
mov    %rax,0x8(%rsp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
mov    %r12d,(%rsp)
mov    %r12d,%r9d
call   10b0 <fprintf@plt>
add    $0x1,%r14d
mov    %r14d,0x4(%rsp)
xor    %r13d,%r13d
lea    0x14(%rsp),%r14
jmp    1270 <_dispatch+0x80>
lea    0xdf6(%rip),%rdi
call   1100 <perror@plt>
nopl   (%rax)
mov    %r14,%rdi
call   10c0 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1110 <FD_SET@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1110 <FD_SET@plt>
test   $0x1,%r13b
jne    129d <_dispatch+0xad>
mov    %r15d,%edi
mov    %r14,%rsi
call   1110 <FD_SET@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10d0 <select@plt>
test   %eax,%eax
lea    0x2df7(%rip),%r12
jns    12d5 <_dispatch+0xe5>
mov    0x2d16(%rip),%rax
mov    (%rax),%rax
mov    0x2d04(%rip),%rcx
cmp    (%rcx),%rax
jne    139e <_dispatch+0x1ae>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     12fc <_dispatch+0x10c>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
mov    (%rsp),%edx
call   1060 <_demultiplex_slip@plt>
test   %rax,%rax
js     13e1 <_dispatch+0x1f1>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1330 <_dispatch+0x140>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1770,%edx
call   10a0 <read@plt>
test   %rax,%rax
jle    1261 <_dispatch+0x71>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %rax,%rdx
call   1090 <_write_escaped@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1270 <_dispatch+0x80>
mov    %r15d,%edi
lea    0x2d62(%rip),%rsi
mov    $0x1770,%edx
call   10a0 <read@plt>
test   %rax,%rax
je     13af <_dispatch+0x1bf>
js     138d <_dispatch+0x19d>
mov    %rax,%r12
mov    %ebp,%edi
mov    $0xa,%esi
call   10f0 <_write_char@plt>
test   %rax,%rax
js     1270 <_dispatch+0x80>
mov    %ebp,%edi
lea    0x2d30(%rip),%rsi
mov    %r12,%rdx
call   1090 <_write_escaped@plt>
jmp    1270 <_dispatch+0x80>
lea    0xd05(%rip),%rdi
call   1100 <perror@plt>
jmp    1270 <_dispatch+0x80>
lea    0xc96(%rip),%rdi
call   1100 <perror@plt>
jmp    12d5 <_dispatch+0xe5>
mov    0x2c2a(%rip),%rax
mov    (%rax),%esi
lea    0xcbb(%rip),%rdi
call   1070 <fputs@plt>
mov    %r15d,%edi
call   1030 <isatty@plt>
test   %rax,%rax
jne    141d <_dispatch+0x22d>
mov    %r15d,%edi
call   1080 <close@plt>
mov    $0x1,%r13b
jmp    1270 <_dispatch+0x80>
mov    0x2bf8(%rip),%rax
mov    (%rax),%esi
lea    0xc51(%rip),%rdi
call   1070 <fputs@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebx
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bbc(%rip),%rax
mov    (%rax),%esi
lea    0xc5d(%rip),%rdi
call   1070 <fputs@plt>
xor    %ebx,%ebx
jmp    1402 <_dispatch+0x212>

LLVM IR (-O0):
@_dispatch.buffer = internal global [1500 x i32] zeroinitializer
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [57 x i8] c"Starting dispatch. TUN: %d, Stream: %d, In: %d, Out: %d\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [7 x i8] c"select\00"
@.str.3 = [28 x i8] c"Connection lost to serial.\0A\00"
@.str.4 = [28 x i8] c"Error reading TUN interface\00"
@.str.5 = [16 x i8] c"EOF from input\0A\00"
@.str.6 = [15 x i8] c"Exit by user.\0A\00"
@.str.7 = [25 x i8] c"Error reading from input\00"
define i32 @_dispatch(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 i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %4
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load i32, i32* %5
br label %28
26: ; preds = %20
%27 = load i32, i32* %7
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ %25, %24 ], [ %27, %26 ]
br label %40
30: ; preds = %4
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load i32, i32* %6
br label %38
36: ; preds = %30
%37 = load i32, i32* %7
br label %38
38: ; preds = %36, %34
%39 = phi i32 [ %35, %34 ], [ %37, %36 ]
br label %40
40: ; preds = %38, %28
%41 = phi i32 [ %29, %28 ], [ %39, %38 ]
store i32 %41, i32* %10
store i32 1, i32* %11
store i32 0, i32* %12
%42 = load i32, i32* %6
%43 = call i32* @fdopen(i32 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %43, i32** %13
%44 = load i32, i32* @stderr
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %46, i32 %47, i32 %48)
br label %50
50: ; preds = %40, %98, %125, %129, %135, %140
%51 = call i32 @FD_ZERO(i32* %9)
%52 = load i32, i32* %5
%53 = call i32 @FD_SET(i32 %52, i32* %9)
%54 = load i32, i32* %6
%55 = call i32 @FD_SET(i32 %54, i32* %9)
%56 = load i32, i32* %11
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32, i32* %7
%60 = call i32 @FD_SET(i32 %59, i32* %9)
br label %61
61: ; preds = %58, %50
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
%64 = call i32 @select(i32 %63, i32* %9, i32* null, i32* null, i32* null)
store i32 %64, i32* %14
%65 = load i32, i32* %14
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %73
67: ; preds = %61
%68 = load i64, i64* @errno
%69 = load i64, i64* @EINTR
%70 = icmp ne i64 %68, %69
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %73
73: ; preds = %71, %67, %61
%74 = load i32, i32* %6
%75 = call i64 @FD_ISSET(i32 %74, i32* %9)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %89
77: ; preds = %73
%78 = load i32*, i32** %13
%79 = load i32, i32* %5
%80 = load i32, i32* %8
%81 = call i64 @_demultiplex_slip(i32* %78, i32 %79, i32 %80)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %77
%84 = load i32, i32* @stderr
%85 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %84)
store i32 -1, i32* %12
%86 = load i32, i32* %6
%87 = call i32 @close(i32 %86)
br label %141
88: ; preds = %77
br label %89
89: ; preds = %88, %73
%90 = load i32, i32* %5
%91 = call i64 @FD_ISSET(i32 %90, i32* %9)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %104
93: ; preds = %89
%94 = load i32, i32* %5
%95 = call i64 @read(i32 %94, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i32 6000)
store i64 %95, i64* %15
%96 = load i64, i64* %15
%97 = icmp sle i64 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %93
%99 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %50
100: ; preds = %93
%101 = load i32, i32* %6
%102 = load i64, i64* %15
%103 = call i32 @_write_escaped(i32 %101, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i64 %102)
br label %104
104: ; preds = %100, %89
%105 = load i32, i32* %7
%106 = call i64 @FD_ISSET(i32 %105, i32* %9)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %140
108: ; preds = %104
%109 = load i32, i32* %7
%110 = call i64 @read(i32 %109, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i32 6000)
store i64 %110, i64* %16
%111 = load i64, i64* %16
%112 = icmp eq i64 %111, 0
br i1 %112, label %113, label %126
113: ; preds = %108
%114 = load i32, i32* @stderr
%115 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %114)
%116 = load i32, i32* %7
%117 = call i64 @isatty(i32 %116)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %113
%120 = load i32, i32* @stderr
%121 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %120)
br label %141
122: ; preds = %113
%123 = load i32, i32* %7
%124 = call i32 @close(i32 %123)
store i32 0, i32* %11
br label %125
125: ; preds = %122
br label %50
126: ; preds = %108
%127 = load i64, i64* %16
%128 = icmp slt i64 %127, 0
br i1 %128, label %129, label %131
129: ; preds = %126
%130 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %50
131: ; preds = %126
%132 = load i32, i32* %6
%133 = call i64 @_write_char(i32 %132, i32 10)
%134 = icmp slt i64 %133, 0
br i1 %134, label %135, label %136
135: ; preds = %131
br label %50
136: ; preds = %131
%137 = load i32, i32* %6
%138 = load i64, i64* %16
%139 = call i32 @_write_escaped(i32 %137, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i64 %138)
br label %140
140: ; preds = %136, %104
br label %50
141: ; preds = %119, %83
%142 = load i32*, i32** %13
%143 = call i32 @fclose(i32* %142)
%144 = load i32, i32* %12
ret i32 %144
}

LLVM IR (-O2):
@_dispatch.buffer = internal global [1500 x i32] zeroinitializer
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [57 x i8] c"Starting dispatch. TUN: %d, Stream: %d, In: %d, Out: %d\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [7 x i8] c"select\00"
@.str.3 = [28 x i8] c"Connection lost to serial.\0A\00"
@.str.4 = [28 x i8] c"Error reading TUN interface\00"
@.str.5 = [16 x i8] c"EOF from input\0A\00"
@.str.6 = [15 x i8] c"Exit by user.\0A\00"
@.str.7 = [25 x i8] c"Error reading from input\00"
define i32 @_dispatch(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp sgt i32 %0, %2
%8 = select i1 %7, i32 %0, i32 %2
%9 = icmp sgt i32 %8, %1
%10 = select i1 %9, i32 %8, i32 %1
%11 = tail call i32* @fdopen(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3)
%14 = add nsw i32 %10, 1
br label %15
15: ; preds = %66, %4
%16 = phi i1 [ true, %66 ], [ false, %4 ]
br label %17
17: ; preds = %75, %15
%18 = call i32 @FD_ZERO(i32* %5)
%19 = call i32 @FD_SET(i32 %0, i32* %5)
%20 = call i32 @FD_SET(i32 %1, i32* %5)
br i1 %16, label %23, label %21
21: ; preds = %17
%22 = call i32 @FD_SET(i32 %2, i32* %5)
br label %23
23: ; preds = %21, %17
%24 = call i32 @select(i32 %14, i32* %5, i32* null, i32* null, i32* null)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp eq i64 %27, %28
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %26, %23
%33 = call i64 @FD_ISSET(i32 %1, i32* %5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %32
%36 = call i64 @_demultiplex_slip(i32* %11, i32 %0, i32 %3)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = call i32 @close(i32 %1)
br label %78
42: ; preds = %35, %32
%43 = call i64 @FD_ISSET(i32 %0, i32* %5)
%44 = icmp eq i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %42
%46 = call i64 @read(i32 %0, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i32 6000)
%47 = icmp slt i64 %46, 1
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %75
50: ; preds = %45
%51 = call i32 @_write_escaped(i32 %1, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i64 %46)
br label %52
52: ; preds = %50, %42
%53 = call i64 @FD_ISSET(i32 %2, i32* %5)
%54 = icmp eq i64 %53, 0
br i1 %54, label %75, label %55
55: ; preds = %52
%56 = call i64 @read(i32 %2, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i32 6000)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = call i64 @isatty(i32 %2)
%62 = icmp eq i64 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %64)
br label %78
66: ; preds = %58
%67 = call i32 @close(i32 %2)
br label %15
68: ; preds = %55
%69 = icmp slt i64 %56, 0
br i1 %69, label %70, label %72
70: ; preds = %68
%71 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %75
72: ; preds = %68
%73 = call i64 @_write_char(i32 %1, i32 10)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %72, %70, %52, %76, %48
br label %17
76: ; preds = %72
%77 = call i32 @_write_escaped(i32 %1, i32* getelementptr inbounds ([1500 x i32], [1500 x i32]* @_dispatch.buffer, i64 0, i64 0), i64 %56)
br label %75
78: ; preds = %63, %38
%79 = phi i32 [ -1, %38 ], [ 0, %63 ]
%80 = call i32 @fclose(i32* %11)
ret i32 %79
}