#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__ uint32_t;
struct pollfd {
  int fd;
  int events;
  int revents;
};
typedef scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ ETIMEDOUT;
int POLLERR;
int POLLHUP;
int POLLIN;
int POLLOUT;
scalar_t__ errno;
double monotonic_seconds();
scalar_t__ poll(struct pollfd *, int, scalar_t__);
scalar_t__ read(int, int /*<<< orphan*/ *, scalar_t__);
scalar_t__ write(int, int /*<<< orphan*/ *, scalar_t__);
int32_t streamtoforward(int srcsock, int dstsock, void *buff, uint32_t leng,
                        uint32_t rcvd, uint32_t sent, uint32_t msecto) {
  int32_t i;
  struct pollfd pfd[2];
  double s, c;
  uint32_t msecpassed;
  s = 0.0;
  pfd[0].fd = srcsock;
  pfd[0].events = POLLIN;
  pfd[0].revents = 0;
  pfd[1].fd = dstsock;
  pfd[1].events = POLLOUT;
  pfd[1].revents = 0;
  while (1) {
    if (rcvd < leng) {
      i = read(srcsock, ((uint8_t *)buff) + rcvd, leng - rcvd);
      if (i == 0) {
        leng = rcvd;
      }
      if (i > 0) {
        rcvd += i;
      } else if ((errno != EAGAIN)) {
        return -1;
      }
    }
    if (pfd[0].revents & POLLHUP) {
      leng = rcvd;
    }
    if (rcvd > sent) {
      i = write(dstsock, ((uint8_t *)buff) + sent, rcvd - sent);
      if (i > 0) {
        sent += i;
      } else if ((errno != EAGAIN)) {
        return -1;
      }
    }
    if (rcvd >= leng && sent >= leng) {
      break;
    }
    if (s == 0.0) {
      s = monotonic_seconds();
      msecpassed = 0;
    } else {
      c = monotonic_seconds();
      msecpassed = (c - s) * 1000.0;
      if (msecpassed >= msecto) {
        errno = ETIMEDOUT;
        return -1;
      }
    }
    pfd[0].revents = 0;
    pfd[1].revents = 0;
    if (rcvd == leng) {
      if (poll(pfd + 1, 1, msecto - msecpassed) < 0) {
        if (errno != EINTR) {
          return -1;
        } else {
          continue;
        }
      }
      if (pfd[1].revents & (POLLERR | POLLHUP)) {
        return -1;
      }
      pfd[0].revents = 0;
    } else if (rcvd == sent) {
      if (poll(pfd, 1, msecto - msecpassed) < 0) {
        if (errno != EINTR) {
          return -1;
        } else {
          continue;
        }
      }
      if (pfd[0].revents & POLLERR) {
        return -1;
      }
      pfd[1].revents = 0;
    } else {
      if (poll(pfd, 2, msecto - msecpassed) < 0) {
        if (errno != EINTR) {
          return -1;
        } else {
          continue;
        }
      }
      if ((pfd[0].revents & POLLERR) ||
          (pfd[1].revents & (POLLERR | POLLHUP))) {
        return -1;
      }
    }
    if ((pfd[0].revents & (POLLIN | POLLHUP)) == 0 &&
        (pfd[1].revents & POLLOUT) == 0) {
      errno = ETIMEDOUT;
      return -1;
    }
  }
  return leng;
}


x86 assembly (clang, -O0):
<streamtoforward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    122d <streamtoforward+0xed>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
sub    -0x28(%rbp),%rdx
call   1040 <read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e0 <streamtoforward+0xa0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x38(%rbp)
jle    11fc <streamtoforward+0xbc>
mov    -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1228 <streamtoforward+0xe8>
mov    0x2dbd(%rip),%rax
mov    (%rax),%rax
mov    0x2d93(%rip),%rcx
cmp    (%rcx),%rax
je     1223 <streamtoforward+0xe3>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    1228 <streamtoforward+0xe8>
jmp    122d <streamtoforward+0xed>
mov    -0x48(%rbp),%eax
mov    0x2da9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     124a <streamtoforward+0x10a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jle    12c8 <streamtoforward+0x188>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x28(%rbp),%rdx
sub    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jle    1297 <streamtoforward+0x157>
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    12c3 <streamtoforward+0x183>
mov    0x2d22(%rip),%rax
mov    (%rax),%rax
mov    0x2cf8(%rip),%rcx
cmp    (%rcx),%rax
je     12be <streamtoforward+0x17e>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    12c3 <streamtoforward+0x183>
jmp    12c8 <streamtoforward+0x188>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     12e9 <streamtoforward+0x1a9>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     12e9 <streamtoforward+0x1a9>
jmp    1599 <streamtoforward+0x459>
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    131a <streamtoforward+0x1da>
jp     131a <streamtoforward+0x1da>
mov    $0x0,%al
call   1060 <monotonic_seconds@plt>
movsd  %xmm0,-0x58(%rbp)
movq   $0x0,-0x68(%rbp)
jmp    1379 <streamtoforward+0x239>
mov    $0x0,%al
call   1060 <monotonic_seconds@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
movsd  0xcc8(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
cmp    0x10(%rbp),%rax
jl     1374 <streamtoforward+0x234>
mov    0x2c5e(%rip),%rax
mov    (%rax),%rcx
mov    0x2c5c(%rip),%rax
mov    %rcx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    1379 <streamtoforward+0x239>
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    141e <streamtoforward+0x2de>
lea    -0x50(%rbp),%rdi
add    $0xc,%rdi
mov    0x10(%rbp),%rdx
sub    -0x68(%rbp),%rdx
mov    $0x1,%esi
call   1050 <poll@plt>
cmp    $0x0,%rax
jge    13e5 <streamtoforward+0x2a5>
mov    0x2c00(%rip),%rax
mov    (%rax),%rax
mov    0x2be6(%rip),%rcx
cmp    (%rcx),%rax
je     13e0 <streamtoforward+0x2a0>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    119c <streamtoforward+0x5c>
mov    -0x3c(%rbp),%eax
mov    0x2be9(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2be8(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1412 <streamtoforward+0x2d2>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
movl   $0x0,-0x48(%rbp)
jmp    153e <streamtoforward+0x3fe>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    14a6 <streamtoforward+0x366>
lea    -0x50(%rbp),%rdi
mov    0x10(%rbp),%rdx
sub    -0x68(%rbp),%rdx
mov    $0x1,%esi
call   1050 <poll@plt>
cmp    $0x0,%rax
jge    1478 <streamtoforward+0x338>
mov    0x2b6d(%rip),%rax
mov    (%rax),%rax
mov    0x2b53(%rip),%rcx
cmp    (%rcx),%rax
je     1473 <streamtoforward+0x333>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    119c <streamtoforward+0x5c>
mov    -0x48(%rbp),%eax
mov    0x2b56(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     149a <streamtoforward+0x35a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
movl   $0x0,-0x3c(%rbp)
jmp    1539 <streamtoforward+0x3f9>
lea    -0x50(%rbp),%rdi
mov    0x10(%rbp),%rdx
sub    -0x68(%rbp),%rdx
mov    $0x2,%esi
call   1050 <poll@plt>
cmp    $0x0,%rax
jge    14f2 <streamtoforward+0x3b2>
mov    0x2af3(%rip),%rax
mov    (%rax),%rax
mov    0x2ad9(%rip),%rcx
cmp    (%rcx),%rax
je     14ed <streamtoforward+0x3ad>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    119c <streamtoforward+0x5c>
mov    -0x48(%rbp),%eax
mov    0x2adc(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1527 <streamtoforward+0x3e7>
mov    -0x3c(%rbp),%eax
mov    0x2ac7(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2ac6(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1534 <streamtoforward+0x3f4>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    1539 <streamtoforward+0x3f9>
jmp    153e <streamtoforward+0x3fe>
mov    -0x48(%rbp),%eax
mov    0x2a88(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2a8f(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1594 <streamtoforward+0x454>
mov    -0x3c(%rbp),%eax
mov    0x2a90(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1594 <streamtoforward+0x454>
mov    0x2a3e(%rip),%rax
mov    (%rax),%rcx
mov    0x2a3c(%rip),%rax
mov    %rcx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    15a1 <streamtoforward+0x461>
jmp    119c <streamtoforward+0x5c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<streamtoforward>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    0x70(%rsp),%r13
mov    %edi,0x34(%rsp)
mov    %edi,0x10(%rsp)
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
movl   $0x0,0x18(%rsp)
mov    %esi,0x30(%rsp)
mov    %esi,0x1c(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movl   $0x0,0x24(%rsp)
mov    0x2e40(%rip),%rbp
xorpd  %xmm0,%xmm0
jmp    11d0 <streamtoforward+0x90>
cs nopw 0x0(%rax,%rax,1)
mov    0x2e09(%rip),%rax
mov    (%rax),%rax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
movsd  0x8(%rsp),%xmm0
jne    13f2 <streamtoforward+0x2b2>
mov    %r15,%rdx
sub    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
jle    1220 <streamtoforward+0xe0>
lea    (%r12,%rbx,4),%rsi
mov    0x34(%rsp),%edi
call   1040 <read@plt>
test   %rax,%rax
cmove  %rbx,%r15
jle    11f9 <streamtoforward+0xb9>
add    %rax,%rbx
jmp    1220 <streamtoforward+0xe0>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
mov    0x2d96(%rip),%rcx
cmp    (%rcx),%rax
jne    13f2 <streamtoforward+0x2b2>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%rbp),%eax
test   %eax,0x18(%rsp)
cmovne %rbx,%r15
mov    %rbx,%rdx
sub    %r14,%rdx
jle    1270 <streamtoforward+0x130>
lea    (%r12,%r14,4),%rsi
mov    0x30(%rsp),%edi
call   1030 <write@plt>
test   %rax,%rax
jle    124a <streamtoforward+0x10a>
add    %rax,%r14
jmp    1270 <streamtoforward+0x130>
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rax
jne    13f2 <streamtoforward+0x2b2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r15,%rbx
jl     127e <streamtoforward+0x13e>
cmp    %r15,%r14
jge    13fb <streamtoforward+0x2bb>
xor    %eax,%eax
call   1060 <monotonic_seconds@plt>
movsd  0x8(%rsp),%xmm1
ucomisd 0xd75(%rip),%xmm1
jne    12a0 <streamtoforward+0x160>
jp     12a0 <streamtoforward+0x160>
movapd %xmm0,%xmm1
xor    %eax,%eax
jmp    12ba <streamtoforward+0x17a>
nop
subsd  %xmm1,%xmm0
mulsd  0xd54(%rip),%xmm0
cvttsd2si %xmm0,%rax
cmp    %r13,%rax
jge    13de <streamtoforward+0x29e>
movl   $0x0,0x18(%rsp)
movl   $0x0,0x24(%rsp)
cmp    %r15,%rbx
movsd  %xmm1,0x8(%rsp)
mov    %r13,%rdx
jne    1330 <streamtoforward+0x1f0>
sub    %rax,%rdx
lea    0x1c(%rsp),%rdi
mov    $0x1,%esi
call   1050 <poll@plt>
test   %rax,%rax
js     11b0 <streamtoforward+0x70>
mov    0x24(%rsp),%ecx
mov    0x0(%rbp),%esi
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
or     %esi,%eax
test   %ecx,%eax
jne    13f2 <streamtoforward+0x2b2>
movl   $0x0,0x18(%rsp)
xor    %edx,%edx
movsd  0x8(%rsp),%xmm0
jmp    13be <streamtoforward+0x27e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
sub    %rax,%rdx
lea    0x10(%rsp),%rdi
cmp    %r14,%rbx
jne    1380 <streamtoforward+0x240>
mov    $0x1,%esi
call   1050 <poll@plt>
test   %rax,%rax
js     11b0 <streamtoforward+0x70>
mov    0x18(%rsp),%edx
mov    0x2c7d(%rip),%rax
test   %edx,(%rax)
jne    13f2 <streamtoforward+0x2b2>
movl   $0x0,0x24(%rsp)
mov    0x0(%rbp),%esi
xor    %ecx,%ecx
movsd  0x8(%rsp),%xmm0
jmp    13be <streamtoforward+0x27e>
nopl   0x0(%rax,%rax,1)
mov    $0x2,%esi
call   1050 <poll@plt>
test   %rax,%rax
js     11b0 <streamtoforward+0x70>
mov    0x18(%rsp),%edx
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffffffffffff,%rax
test   %edx,%edi
jne    13fe <streamtoforward+0x2be>
mov    0x24(%rsp),%ecx
mov    0x0(%rbp),%esi
or     %esi,%edi
test   %ecx,%edi
movsd  0x8(%rsp),%xmm0
jne    13fe <streamtoforward+0x2be>
mov    0x2c0b(%rip),%rax
or     (%rax),%esi
test   %edx,%esi
jne    11d0 <streamtoforward+0x90>
mov    0x2c22(%rip),%rax
test   %ecx,(%rax)
jne    11d0 <streamtoforward+0x90>
mov    0x2bd3(%rip),%rax
mov    (%rax),%rax
mov    0x2bd1(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffffffffffff,%rax
jmp    13fe <streamtoforward+0x2be>
mov    %r15,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@POLLHUP = global i32 0
@ETIMEDOUT = global i64 0
@EINTR = global i64 0
@POLLERR = global i32 0
define i64 @streamtoforward(i32 %0, i32 %1, i8* %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca [2 x %struct.pollfd]
%18 = alloca double
%19 = alloca double
%20 = alloca i64
store i32 %0, i32* %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i64 %3, i64* %12
store i64 %4, i64* %13
store i64 %5, i64* %14
store i64 %6, i64* %15
store double 0.000000e+00, double* %18
%21 = load i32, i32* %9
%22 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%23 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* @POLLIN
%25 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %25, i32 0, i32 1
store i32 %24, i32* %26
%27 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%28 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %27, i32 0, i32 2
store i32 0, i32* %28
%29 = load i32, i32* %10
%30 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = load i32, i32* @POLLOUT
%33 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%34 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %33, i32 0, i32 1
store i32 %32, i32* %34
%35 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%36 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %35, i32 0, i32 2
store i32 0, i32* %36
br label %37
37: ; preds = %7, %153, %183, %207, %245
%38 = load i64, i64* %13
%39 = load i64, i64* %12
%40 = icmp slt i64 %38, %39
br i1 %40, label %41, label %69
41: ; preds = %37
%42 = load i32, i32* %9
%43 = load i8*, i8** %11
%44 = bitcast i8* %43 to i32*
%45 = load i64, i64* %13
%46 = getelementptr inbounds i32, i32* %44, i64 %45
%47 = load i64, i64* %12
%48 = load i64, i64* %13
%49 = sub nsw i64 %47, %48
%50 = call i64 @read(i32 %42, i32* %46, i64 %49)
store i64 %50, i64* %16
%51 = load i64, i64* %16
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %41
%54 = load i64, i64* %13
store i64 %54, i64* %12
br label %55
55: ; preds = %53, %41
%56 = load i64, i64* %16
%57 = icmp sgt i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %55
%59 = load i64, i64* %16
%60 = load i64, i64* %13
%61 = add nsw i64 %60, %59
store i64 %61, i64* %13
br label %68
62: ; preds = %55
%63 = load i64, i64* @errno
%64 = load i64, i64* @EAGAIN
%65 = icmp ne i64 %63, %64
br i1 %65, label %66, label %67
66: ; preds = %62
store i64 -1, i64* %8
br label %248
67: ; preds = %62
br label %68
68: ; preds = %67, %58
br label %69
69: ; preds = %68, %37
%70 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%71 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %70, i32 0, i32 2
%72 = load i32, i32* %71
%73 = load i32, i32* @POLLHUP
%74 = and i32 %72, %73
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %69
%77 = load i64, i64* %13
store i64 %77, i64* %12
br label %78
78: ; preds = %76, %69
%79 = load i64, i64* %13
%80 = load i64, i64* %14
%81 = icmp sgt i64 %79, %80
br i1 %81, label %82, label %105
82: ; preds = %78
%83 = load i32, i32* %10
%84 = load i8*, i8** %11
%85 = bitcast i8* %84 to i32*
%86 = load i64, i64* %14
%87 = getelementptr inbounds i32, i32* %85, i64 %86
%88 = load i64, i64* %13
%89 = load i64, i64* %14
%90 = sub nsw i64 %88, %89
%91 = call i64 @write(i32 %83, i32* %87, i64 %90)
store i64 %91, i64* %16
%92 = load i64, i64* %16
%93 = icmp sgt i64 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %82
%95 = load i64, i64* %16
%96 = load i64, i64* %14
%97 = add nsw i64 %96, %95
store i64 %97, i64* %14
br label %104
98: ; preds = %82
%99 = load i64, i64* @errno
%100 = load i64, i64* @EAGAIN
%101 = icmp ne i64 %99, %100
br i1 %101, label %102, label %103
102: ; preds = %98
store i64 -1, i64* %8
br label %248
103: ; preds = %98
br label %104
104: ; preds = %103, %94
br label %105
105: ; preds = %104, %78
%106 = load i64, i64* %13
%107 = load i64, i64* %12
%108 = icmp sge i64 %106, %107
br i1 %108, label %109, label %114
109: ; preds = %105
%110 = load i64, i64* %14
%111 = load i64, i64* %12
%112 = icmp sge i64 %110, %111
br i1 %112, label %113, label %114
113: ; preds = %109
br label %246
114: ; preds = %109, %105
%115 = load double, double* %18
%116 = fcmp oeq double %115, 0.000000e+00
br i1 %116, label %117, label %119
117: ; preds = %114
%118 = call double (...) @monotonic_seconds()
store double %118, double* %18
store i64 0, i64* %20
br label %132
119: ; preds = %114
%120 = call double (...) @monotonic_seconds()
store double %120, double* %19
%121 = load double, double* %19
%122 = load double, double* %18
%123 = fsub double %121, %122
%124 = fmul double %123, 1.000000e+03
%125 = fptosi double %124 to i64
store i64 %125, i64* %20
%126 = load i64, i64* %20
%127 = load i64, i64* %15
%128 = icmp sge i64 %126, %127
br i1 %128, label %129, label %131
129: ; preds = %119
%130 = load i64, i64* @ETIMEDOUT
store i64 %130, i64* @errno
store i64 -1, i64* %8
br label %248
131: ; preds = %119
br label %132
132: ; preds = %131, %117
%133 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%134 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %133, i32 0, i32 2
store i32 0, i32* %134
%135 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%136 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %135, i32 0, i32 2
store i32 0, i32* %136
%137 = load i64, i64* %13
%138 = load i64, i64* %12
%139 = icmp eq i64 %137, %138
br i1 %139, label %140, label %167
140: ; preds = %132
%141 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%142 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %141, i64 1
%143 = load i64, i64* %15
%144 = load i64, i64* %20
%145 = sub nsw i64 %143, %144
%146 = call i64 @poll(%struct.pollfd* %142, i32 1, i64 %145)
%147 = icmp slt i64 %146, 0
br i1 %147, label %148, label %154
148: ; preds = %140
%149 = load i64, i64* @errno
%150 = load i64, i64* @EINTR
%151 = icmp ne i64 %149, %150
br i1 %151, label %152, label %153
152: ; preds = %148
store i64 -1, i64* %8
br label %248
153: ; preds = %148
br label %37
154: ; preds = %140
%155 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%156 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %155, i32 0, i32 2
%157 = load i32, i32* %156
%158 = load i32, i32* @POLLERR
%159 = load i32, i32* @POLLHUP
%160 = or i32 %158, %159
%161 = and i32 %157, %160
%162 = icmp ne i32 %161, 0
br i1 %162, label %163, label %164
163: ; preds = %154
store i64 -1, i64* %8
br label %248
164: ; preds = %154
%165 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%166 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %165, i32 0, i32 2
store i32 0, i32* %166
br label %227
167: ; preds = %132
%168 = load i64, i64* %13
%169 = load i64, i64* %14
%170 = icmp eq i64 %168, %169
br i1 %170, label %171, label %195
171: ; preds = %167
%172 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%173 = load i64, i64* %15
%174 = load i64, i64* %20
%175 = sub nsw i64 %173, %174
%176 = call i64 @poll(%struct.pollfd* %172, i32 1, i64 %175)
%177 = icmp slt i64 %176, 0
br i1 %177, label %178, label %184
178: ; preds = %171
%179 = load i64, i64* @errno
%180 = load i64, i64* @EINTR
%181 = icmp ne i64 %179, %180
br i1 %181, label %182, label %183
182: ; preds = %178
store i64 -1, i64* %8
br label %248
183: ; preds = %178
br label %37
184: ; preds = %171
%185 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%186 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %185, i32 0, i32 2
%187 = load i32, i32* %186
%188 = load i32, i32* @POLLERR
%189 = and i32 %187, %188
%190 = icmp ne i32 %189, 0
br i1 %190, label %191, label %192
191: ; preds = %184
store i64 -1, i64* %8
br label %248
192: ; preds = %184
%193 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%194 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %193, i32 0, i32 2
store i32 0, i32* %194
br label %226
195: ; preds = %167
%196 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%197 = load i64, i64* %15
%198 = load i64, i64* %20
%199 = sub nsw i64 %197, %198
%200 = call i64 @poll(%struct.pollfd* %196, i32 2, i64 %199)
%201 = icmp slt i64 %200, 0
br i1 %201, label %202, label %208
202: ; preds = %195
%203 = load i64, i64* @errno
%204 = load i64, i64* @EINTR
%205 = icmp ne i64 %203, %204
br i1 %205, label %206, label %207
206: ; preds = %202
store i64 -1, i64* %8
br label %248
207: ; preds = %202
br label %37
208: ; preds = %195
%209 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%210 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %209, i32 0, i32 2
%211 = load i32, i32* %210
%212 = load i32, i32* @POLLERR
%213 = and i32 %211, %212
%214 = icmp ne i32 %213, 0
br i1 %214, label %224, label %215
215: ; preds = %208
%216 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%217 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %216, i32 0, i32 2
%218 = load i32, i32* %217
%219 = load i32, i32* @POLLERR
%220 = load i32, i32* @POLLHUP
%221 = or i32 %219, %220
%222 = and i32 %218, %221
%223 = icmp ne i32 %222, 0
br i1 %223, label %224, label %225
224: ; preds = %215, %208
store i64 -1, i64* %8
br label %248
225: ; preds = %215
br label %226
226: ; preds = %225, %192
br label %227
227: ; preds = %226, %164
%228 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 0
%229 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %228, i32 0, i32 2
%230 = load i32, i32* %229
%231 = load i32, i32* @POLLIN
%232 = load i32, i32* @POLLHUP
%233 = or i32 %231, %232
%234 = and i32 %230, %233
%235 = icmp eq i32 %234, 0
br i1 %235, label %236, label %245
236: ; preds = %227
%237 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %17, i64 0, i64 1
%238 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %237, i32 0, i32 2
%239 = load i32, i32* %238
%240 = load i32, i32* @POLLOUT
%241 = and i32 %239, %240
%242 = icmp eq i32 %241, 0
br i1 %242, label %243, label %245
243: ; preds = %236
%244 = load i64, i64* @ETIMEDOUT
store i64 %244, i64* @errno
store i64 -1, i64* %8
br label %248
245: ; preds = %236, %227
br label %37
246: ; preds = %113
%247 = load i64, i64* %12
store i64 %247, i64* %8
br label %248
248: ; preds = %246, %243, %224, %206, %191, %182, %163, %152, %129, %102, %66
%249 = load i64, i64* %8
ret i64 %249
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@POLLHUP = global i32 0
@ETIMEDOUT = global i64 0
@EINTR = global i64 0
@POLLERR = global i32 0
define i64 @streamtoforward(i32 %0, i32 %1, i8* nocapture %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = alloca [2 x %struct.pollfd]
%9 = bitcast [2 x %struct.pollfd]* %8 to i8*
%10 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%11 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 0
store i32 %0, i32* %11
%12 = load i32, i32* @POLLIN
%13 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 2
store i32 0, i32* %14
%15 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 0
store i32 %1, i32* %15
%16 = load i32, i32* @POLLOUT
%17 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 2
store i32 0, i32* %18
%19 = bitcast i8* %2 to i32*
%20 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1
br label %21
21: ; preds = %136, %7
%22 = phi i64 [ %4, %7 ], [ %41, %136 ]
%23 = phi i64 [ %5, %7 ], [ %61, %136 ]
%24 = phi i64 [ %3, %7 ], [ %47, %136 ]
%25 = phi double [ 0.000000e+00, %7 ], [ %74, %136 ]
%26 = icmp sgt i64 %24, %22
br i1 %26, label %27, label %40
27: ; preds = %21
%28 = getelementptr inbounds i32, i32* %19, i64 %22
%29 = sub nsw i64 %24, %22
%30 = call i64 @read(i32 %0, i32* %28, i64 %29)
%31 = icmp eq i64 %30, 0
%32 = select i1 %31, i64 %22, i64 %24
%33 = icmp sgt i64 %30, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = add nsw i64 %30, %22
br label %40
36: ; preds = %27
%37 = load i64, i64* @errno
%38 = load i64, i64* @EAGAIN
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %143
40: ; preds = %34, %36, %21
%41 = phi i64 [ %35, %34 ], [ %22, %36 ], [ %22, %21 ]
%42 = phi i64 [ %32, %34 ], [ %32, %36 ], [ %24, %21 ]
%43 = load i32, i32* %14
%44 = load i32, i32* @POLLHUP
%45 = and i32 %44, %43
%46 = icmp eq i32 %45, 0
%47 = select i1 %46, i64 %42, i64 %41
%48 = icmp sgt i64 %41, %23
br i1 %48, label %49, label %60
49: ; preds = %40
%50 = getelementptr inbounds i32, i32* %19, i64 %23
%51 = sub nsw i64 %41, %23
%52 = call i64 @write(i32 %1, i32* %50, i64 %51)
%53 = icmp sgt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = add nsw i64 %52, %23
br label %60
56: ; preds = %49
%57 = load i64, i64* @errno
%58 = load i64, i64* @EAGAIN
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %143
60: ; preds = %54, %56, %40
%61 = phi i64 [ %55, %54 ], [ %23, %56 ], [ %23, %40 ]
%62 = icmp slt i64 %41, %47
%63 = icmp slt i64 %61, %47
%64 = select i1 %62, i1 true, i1 %63
br i1 %64, label %65, label %143
65: ; preds = %60
%66 = fcmp oeq double %25, 0.000000e+00
%67 = call double (...) @monotonic_seconds()
br i1 %66, label %73, label %68
68: ; preds = %65
%69 = fsub double %67, %25
%70 = fmul double %69, 1.000000e+03
%71 = fptosi double %70 to i64
%72 = icmp slt i64 %71, %6
br i1 %72, label %73, label %141
73: ; preds = %65, %68
%74 = phi double [ %25, %68 ], [ %67, %65 ]
%75 = phi i64 [ %71, %68 ], [ 0, %65 ]
store i32 0, i32* %14
store i32 0, i32* %18
%76 = icmp eq i64 %41, %47
br i1 %76, label %77, label %93
77: ; preds = %73
%78 = sub nsw i64 %6, %75
%79 = call i64 @poll(%struct.pollfd* %20, i32 1, i64 %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %77
%82 = load i64, i64* @errno
%83 = load i64, i64* @EINTR
%84 = icmp eq i64 %82, %83
br i1 %84, label %136, label %143
85: ; preds = %77
%86 = load i32, i32* %18
%87 = load i32, i32* @POLLERR
%88 = load i32, i32* @POLLHUP
%89 = or i32 %88, %87
%90 = and i32 %89, %86
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %143
92: ; preds = %85
store i32 0, i32* %14
br label %128
93: ; preds = %73
%94 = icmp eq i64 %41, %61
%95 = sub nsw i64 %6, %75
br i1 %94, label %96, label %110
96: ; preds = %93
%97 = call i64 @poll(%struct.pollfd* %10, i32 1, i64 %95)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %96
%100 = load i64, i64* @errno
%101 = load i64, i64* @EINTR
%102 = icmp eq i64 %100, %101
br i1 %102, label %136, label %143
103: ; preds = %96
%104 = load i32, i32* %14
%105 = load i32, i32* @POLLERR
%106 = and i32 %105, %104
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %143
108: ; preds = %103
store i32 0, i32* %18
%109 = load i32, i32* @POLLHUP
br label %128
110: ; preds = %93
%111 = call i64 @poll(%struct.pollfd* %10, i32 2, i64 %95)
%112 = icmp slt i64 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %110
%114 = load i64, i64* @errno
%115 = load i64, i64* @EINTR
%116 = icmp eq i64 %114, %115
br i1 %116, label %136, label %143
117: ; preds = %110
%118 = load i32, i32* %14
%119 = load i32, i32* @POLLERR
%120 = and i32 %119, %118
%121 = icmp eq i32 %120, 0
br i1 %121, label %122, label %143
122: ; preds = %117
%123 = load i32, i32* %18
%124 = load i32, i32* @POLLHUP
%125 = or i32 %124, %119
%126 = and i32 %125, %123
%127 = icmp eq i32 %126, 0
br i1 %127, label %128, label %143
128: ; preds = %108, %122, %92
%129 = phi i32 [ 0, %108 ], [ %123, %122 ], [ %86, %92 ]
%130 = phi i32 [ %109, %108 ], [ %124, %122 ], [ %88, %92 ]
%131 = phi i32 [ %104, %108 ], [ %118, %122 ], [ 0, %92 ]
%132 = load i32, i32* @POLLIN
%133 = or i32 %130, %132
%134 = and i32 %133, %131
%135 = icmp eq i32 %134, 0
br i1 %135, label %137, label %136
136: ; preds = %128, %137, %81, %99, %113
br label %21
137: ; preds = %128
%138 = load i32, i32* @POLLOUT
%139 = and i32 %138, %129
%140 = icmp eq i32 %139, 0
br i1 %140, label %141, label %136
141: ; preds = %137, %68
%142 = load i64, i64* @ETIMEDOUT
store i64 %142, i64* @errno
br label %143
143: ; preds = %60, %117, %122, %113, %103, %99, %85, %81, %56, %36, %141
%144 = phi i64 [ -1, %141 ], [ %47, %60 ], [ -1, %117 ], [ -1, %122 ], [ -1, %113 ], [ -1, %103 ], [ -1, %99 ], [ -1, %85 ], [ -1, %81 ], [ -1, %56 ], [ -1, %36 ]
ret i64 %144
}