#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct pollfd {
  int fd;
  int events;
  int revents;
};
typedef size_t nfds_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ EFAULT;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ EOVERFLOW;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int POLLIN;
int POLLOUT;
int POLLPRI;
int POLLRDBAND;
int POLLRDNORM;
int POLLWRBAND;
int POLLWRNORM;
int compute_revents(int, int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int poll(struct pollfd *pfd, nfds_t nfd, int timeout) {
  fd_set rfds, wfds, efds;
  struct timeval tv;
  struct timeval *ptv;
  int maxfd, rc;
  nfds_t i;
  if (!pfd) {
    errno = EFAULT;
    return -1;
  }
  if (timeout == 0) {
    ptv = &tv;
    ptv->tv_sec = 0;
    ptv->tv_usec = 0;
  } else if (timeout > 0) {
    ptv = &tv;
    ptv->tv_sec = timeout / 1000;
    ptv->tv_usec = (timeout % 1000) * 1000;
  } else if (timeout == (-1))
    ptv = NULL;
  else {
    errno = EINVAL;
    return -1;
  }
  maxfd = -1;
  FD_ZERO(&rfds);
  FD_ZERO(&wfds);
  FD_ZERO(&efds);
  for (i = 0; i < nfd; i++) {
    if (pfd[i].fd < 0)
      continue;
    if (pfd[i].events & (POLLIN | POLLRDNORM))
      FD_SET(pfd[i].fd, &rfds);
    if (pfd[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND))
      FD_SET(pfd[i].fd, &wfds);
    if (pfd[i].events & (POLLPRI | POLLRDBAND))
      FD_SET(pfd[i].fd, &efds);
    if (pfd[i].fd >= maxfd &&
        (pfd[i].events & (POLLIN | POLLOUT | POLLPRI | POLLRDNORM | POLLRDBAND |
                          POLLWRNORM | POLLWRBAND))) {
      maxfd = pfd[i].fd;
      if (maxfd > FD_SETSIZE) {
        errno = EOVERFLOW;
        return -1;
      }
    }
  }
  rc = select(maxfd + 1, &rfds, &wfds, &efds, ptv);
  if (rc < 0)
    return rc;
  rc = 0;
  for (i = 0; i < nfd; i++)
    if (pfd[i].fd < 0)
      pfd[i].revents = 0;
    else {
      int happened =
          compute_revents(pfd[i].fd, pfd[i].events, &rfds, &wfds, &efds);
      if (happened) {
        pfd[i].revents = happened;
        rc++;
      }
    }
  return rc;
}


x86 assembly (clang, -O0):
<poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <poll+0x3c>
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
mov    0x2e32(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <poll+0x3cd>
cmpl   $0x0,-0x1c(%rbp)
jne    11a8 <poll+0x68>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movl   $0x0,0x4(%rax)
jmp    1229 <poll+0xe9>
cmpl   $0x0,-0x1c(%rbp)
jle    11ea <poll+0xaa>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    1224 <poll+0xe4>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1201 <poll+0xc1>
movq   $0x0,-0x38(%rbp)
jmp    121f <poll+0xdf>
mov    0x2d90(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8f(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <poll+0x3cd>
jmp    1224 <poll+0xe4>
jmp    1229 <poll+0xe9>
movl   $0xffffffff,-0x3c(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <FD_ZERO@plt>
lea    -0x24(%rbp),%rdi
call   1030 <FD_ZERO@plt>
lea    -0x28(%rbp),%rdi
call   1030 <FD_ZERO@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1419 <poll+0x2d9>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    127b <poll+0x13b>
jmp    1408 <poll+0x2c8>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2d27(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d26(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     12be <poll+0x17e>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2d1c(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2cf3(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c9a(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     130a <poll+0x1ca>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x24(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2cb8(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2c67(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     134d <poll+0x20d>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%eax
cmp    -0x3c(%rbp),%eax
jl     1403 <poll+0x2c3>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2c3e(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2c6d(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c4c(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c2b(%rip),%rdx
or     (%rdx),%ecx
mov    0x2bf2(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c29(%rip),%rdx
or     (%rdx),%ecx
mov    0x2bd0(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1403 <poll+0x2c3>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2bd0(%rip),%rcx
cmp    (%rcx),%eax
jle    13fe <poll+0x2be>
mov    0x2bf9(%rip),%rax
mov    (%rax),%ecx
mov    0x2bb0(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <poll+0x3cd>
jmp    1403 <poll+0x2c3>
jmp    1408 <poll+0x2c8>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1253 <poll+0x113>
mov    -0x3c(%rbp),%edi
add    $0x1,%edi
mov    -0x38(%rbp),%r8
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <select@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    144c <poll+0x30c>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    150d <poll+0x3cd>
movl   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1507 <poll+0x3c7>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    1496 <poll+0x356>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
jmp    14f1 <poll+0x3b1>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1050 <compute_revents@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     14ec <poll+0x3ac>
mov    -0x4c(%rbp),%ecx
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rdx
add    %rdx,%rax
mov    %ecx,0x8(%rax)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    14f1 <poll+0x3b1>
jmp    14f6 <poll+0x3b6>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    145b <poll+0x31b>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     1184 <poll+0x44>
mov    %rsi,%r15
mov    %rdi,%rbx
test   %edx,%edx
je     1190 <poll+0x50>
jle    1395 <poll+0x255>
mov    %edx,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,0x18(%rsp)
imul   $0x3e8,%eax,%eax
sub    %eax,%edx
imul   $0x3e8,%edx,%eax
jmp    119a <poll+0x5a>
mov    0x2e6d(%rip),%rax
jmp    13a1 <poll+0x261>
movl   $0x0,0x18(%rsp)
xor    %eax,%eax
mov    %eax,0x1c(%rsp)
lea    0x18(%rsp),%rbp
lea    0x14(%rsp),%rdi
call   1030 <FD_ZERO@plt>
lea    0x10(%rsp),%rdi
call   1030 <FD_ZERO@plt>
lea    0xc(%rsp),%rdi
call   1030 <FD_ZERO@plt>
test   %r15,%r15
je     1373 <poll+0x233>
mov    %rbp,0x20(%rsp)
lea    0x4(%rbx),%r12
mov    $0xffffffff,%ebp
mov    0x2db1(%rip),%r13
mov    %r15,%r14
jmp    11fe <poll+0xbe>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xc,%r12
add    $0xffffffffffffffff,%r14
je     12ef <poll+0x1af>
mov    -0x4(%r12),%edi
test   %edi,%edi
js     11f0 <poll+0xb0>
mov    (%r12),%eax
mov    0x2dae(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d9d(%rip),%rdx
or     (%rdx),%ecx
test   %eax,%ecx
je     122f <poll+0xef>
lea    0x14(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    (%r12),%eax
mov    0x2d9a(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2db1(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d38(%rip),%rdx
or     (%rdx),%ecx
test   %eax,%ecx
je     1261 <poll+0x121>
mov    -0x4(%r12),%edi
lea    0x10(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    (%r12),%eax
mov    0x0(%r13),%ecx
mov    0x2d6c(%rip),%rdx
or     (%rdx),%ecx
test   %eax,%ecx
je     1281 <poll+0x141>
mov    -0x4(%r12),%edi
lea    0xc(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    -0x4(%r12),%eax
cmp    %ebp,%eax
jl     11f0 <poll+0xb0>
mov    0x2d5b(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d1a(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d31(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d10(%rip),%rdx
or     (%rdx),%ecx
or     0x0(%r13),%ecx
mov    0x2d13(%rip),%rdx
or     (%rdx),%ecx
mov    0x2cba(%rip),%rdx
or     (%rdx),%ecx
test   %ecx,(%r12)
je     11f0 <poll+0xb0>
mov    %eax,%ebp
mov    0x2ccd(%rip),%rcx
cmp    (%rcx),%eax
jle    11f0 <poll+0xb0>
mov    0x2cf6(%rip),%rax
jmp    13a1 <poll+0x261>
add    $0x1,%ebp
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    0x20(%rsp),%r8
call   1040 <select@plt>
mov    %eax,%ebp
sar    $0x1f,%ebp
and    %eax,%ebp
test   %eax,%eax
js     13b1 <poll+0x271>
test   %r15,%r15
je     13b1 <poll+0x271>
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
jmp    1350 <poll+0x210>
nopl   0x0(%rax)
movl   $0x0,(%rbx)
add    $0xc,%rbx
add    $0xffffffffffffffff,%r15
je     13b1 <poll+0x271>
mov    -0x8(%rbx),%edi
test   %edi,%edi
js     1340 <poll+0x200>
mov    -0x4(%rbx),%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <compute_revents@plt>
test   %eax,%eax
je     1346 <poll+0x206>
mov    %eax,(%rbx)
add    $0x1,%ebp
jmp    1346 <poll+0x206>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
xor    %edi,%edi
mov    %rbp,%r8
call   1040 <select@plt>
mov    %eax,%ebp
sar    $0x1f,%ebp
and    %eax,%ebp
jmp    13b1 <poll+0x271>
cmp    $0xffffffff,%edx
je     13c2 <poll+0x282>
mov    0x2bf7(%rip),%rax
mov    (%rax),%eax
mov    0x2bf6(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11a3 <poll+0x63>

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
%struct.timeval = type { i32, i32 }
@EFAULT = global i32 0
@errno = global i32 0
@EINVAL = global i32 0
@POLLIN = global i32 0
@POLLRDNORM = global i32 0
@POLLOUT = global i32 0
@POLLWRNORM = global i32 0
@POLLWRBAND = global i32 0
@POLLPRI = global i32 0
@POLLRDBAND = global i32 0
@FD_SETSIZE = global i32 0
@EOVERFLOW = global i32 0
define i32 @poll(%struct.pollfd* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast %struct.timeval* %7 to i8*
%12 = icmp eq %struct.pollfd* %0, null
br i1 %12, label %132, label %13
13: ; preds = %3
%14 = icmp eq i32 %2, 0
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 0, i32* %16
br label %26
17: ; preds = %13
%18 = icmp sgt i32 %2, 0
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = udiv i32 %2, 1000
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 %20, i32* %21
%22 = urem i32 %2, 1000
%23 = mul nuw nsw i32 %22, 1000
br label %26
24: ; preds = %17
%25 = icmp eq i32 %2, -1
br i1 %25, label %29, label %132
26: ; preds = %15, %19
%27 = phi i32 [ %23, %19 ], [ 0, %15 ]
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i32 %27, i32* %28
br label %29
29: ; preds = %26, %24
%30 = phi %struct.timeval* [ null, %24 ], [ %7, %26 ]
%31 = call i32 @FD_ZERO(i32* %4)
%32 = call i32 @FD_ZERO(i32* %5)
%33 = call i32 @FD_ZERO(i32* %6)
%34 = icmp eq i64 %1, 0
br i1 %34, label %108, label %35
35: ; preds = %29, %98
%36 = phi i64 [ %100, %98 ], [ 0, %29 ]
%37 = phi i32 [ %99, %98 ], [ -1, %29 ]
%38 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %36, i32 0
%39 = load i32, i32* %38
%40 = icmp slt i32 %39, 0
br i1 %40, label %98, label %41
41: ; preds = %35
%42 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %36, i32 1
%43 = load i32, i32* %42
%44 = load i32, i32* @POLLIN
%45 = load i32, i32* @POLLRDNORM
%46 = or i32 %45, %44
%47 = and i32 %46, %43
%48 = icmp eq i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %41
%50 = call i32 @FD_SET(i32 %39, i32* %4)
%51 = load i32, i32* %42
br label %52
52: ; preds = %49, %41
%53 = phi i32 [ %51, %49 ], [ %43, %41 ]
%54 = load i32, i32* @POLLOUT
%55 = load i32, i32* @POLLWRNORM
%56 = or i32 %55, %54
%57 = load i32, i32* @POLLWRBAND
%58 = or i32 %56, %57
%59 = and i32 %58, %53
%60 = icmp eq i32 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %52
%62 = load i32, i32* %38
%63 = call i32 @FD_SET(i32 %62, i32* %5)
%64 = load i32, i32* %42
br label %65
65: ; preds = %61, %52
%66 = phi i32 [ %64, %61 ], [ %53, %52 ]
%67 = load i32, i32* @POLLPRI
%68 = load i32, i32* @POLLRDBAND
%69 = or i32 %68, %67
%70 = and i32 %69, %66
%71 = icmp eq i32 %70, 0
br i1 %71, label %75, label %72
72: ; preds = %65
%73 = load i32, i32* %38
%74 = call i32 @FD_SET(i32 %73, i32* %6)
br label %75
75: ; preds = %72, %65
%76 = load i32, i32* %38
%77 = icmp slt i32 %76, %37
br i1 %77, label %98, label %78
78: ; preds = %75
%79 = load i32, i32* %42
%80 = load i32, i32* @POLLIN
%81 = load i32, i32* @POLLOUT
%82 = or i32 %81, %80
%83 = load i32, i32* @POLLPRI
%84 = or i32 %82, %83
%85 = load i32, i32* @POLLRDNORM
%86 = or i32 %84, %85
%87 = load i32, i32* @POLLRDBAND
%88 = or i32 %86, %87
%89 = load i32, i32* @POLLWRNORM
%90 = or i32 %88, %89
%91 = load i32, i32* @POLLWRBAND
%92 = or i32 %90, %91
%93 = and i32 %92, %79
%94 = icmp eq i32 %93, 0
br i1 %94, label %98, label %95
95: ; preds = %78
%96 = load i32, i32* @FD_SETSIZE
%97 = icmp sgt i32 %76, %96
br i1 %97, label %132, label %98
98: ; preds = %75, %78, %95, %35
%99 = phi i32 [ %37, %35 ], [ %76, %95 ], [ %37, %78 ], [ %37, %75 ]
%100 = add nuw i64 %36, 1
%101 = icmp eq i64 %100, %1
br i1 %101, label %102, label %35
102: ; preds = %98
%103 = add nsw i32 %99, 1
%104 = call i32 @select(i32 %103, i32* %4, i32* %5, i32* %6, %struct.timeval* %30)
%105 = icmp slt i32 %104, 0
%106 = or i1 %105, %34
%107 = select i1 %105, i32 %104, i32 0
br i1 %106, label %135, label %112
108: ; preds = %29
%109 = call i32 @select(i32 0, i32* %4, i32* %5, i32* %6, %struct.timeval* %30)
%110 = icmp slt i32 %109, 0
%111 = select i1 %110, i32 %109, i32 0
br label %135
112: ; preds = %102, %128
%113 = phi i64 [ %130, %128 ], [ 0, %102 ]
%114 = phi i32 [ %129, %128 ], [ 0, %102 ]
%115 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %113, i32 0
%116 = load i32, i32* %115
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %112
%119 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %113, i32 2
store i32 0, i32* %119
br label %128
120: ; preds = %112
%121 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %113, i32 1
%122 = load i32, i32* %121
%123 = call i32 @compute_revents(i32 %116, i32 %122, i32* %4, i32* %5, i32* %6)
%124 = icmp eq i32 %123, 0
br i1 %124, label %128, label %125
125: ; preds = %120
%126 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %113, i32 2
store i32 %123, i32* %126
%127 = add nsw i32 %114, 1
br label %128
128: ; preds = %120, %125, %118
%129 = phi i32 [ %114, %118 ], [ %127, %125 ], [ %114, %120 ]
%130 = add nuw i64 %113, 1
%131 = icmp eq i64 %130, %1
br i1 %131, label %135, label %112
132: ; preds = %95, %24, %3
%133 = phi i32* [ @EFAULT, %3 ], [ @EINVAL, %24 ], [ @EOVERFLOW, %95 ]
%134 = load i32, i32* %133
store i32 %134, i32* @errno
br label %135
135: ; preds = %128, %108, %132, %102
%136 = phi i32 [ %107, %102 ], [ %111, %108 ], [ -1, %132 ], [ %129, %128 ]
ret i32 %136
}