#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 && nfd) {
    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    1187 <poll+0x47>
cmpq   $0x0,-0x18(%rbp)
je     1187 <poll+0x47>
mov    0x2e88(%rip),%rax
mov    (%rax),%ecx
mov    0x2e27(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1518 <poll+0x3d8>
cmpl   $0x0,-0x1c(%rbp)
jne    11b3 <poll+0x73>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movl   $0x0,0x4(%rax)
jmp    1234 <poll+0xf4>
cmpl   $0x0,-0x1c(%rbp)
jle    11f5 <poll+0xb5>
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    122f <poll+0xef>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    120c <poll+0xcc>
movq   $0x0,-0x38(%rbp)
jmp    122a <poll+0xea>
mov    0x2d85(%rip),%rax
mov    (%rax),%ecx
mov    0x2d84(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1518 <poll+0x3d8>
jmp    122f <poll+0xef>
jmp    1234 <poll+0xf4>
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    1424 <poll+0x2e4>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    1286 <poll+0x146>
jmp    1413 <poll+0x2d3>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2d1c(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d1b(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     12c9 <poll+0x189>
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    0x2d11(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2ce8(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c8f(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1315 <poll+0x1d5>
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    0x2cad(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2c5c(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1358 <poll+0x218>
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     140e <poll+0x2ce>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2c33(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2c62(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c41(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c20(%rip),%rdx
or     (%rdx),%ecx
mov    0x2be7(%rip),%rdx
or     (%rdx),%ecx
mov    0x2c1e(%rip),%rdx
or     (%rdx),%ecx
mov    0x2bc5(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     140e <poll+0x2ce>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2bc5(%rip),%rcx
cmp    (%rcx),%eax
jle    1409 <poll+0x2c9>
mov    0x2bee(%rip),%rax
mov    (%rax),%ecx
mov    0x2ba5(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1518 <poll+0x3d8>
jmp    140e <poll+0x2ce>
jmp    1413 <poll+0x2d3>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    125e <poll+0x11e>
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    1457 <poll+0x317>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1518 <poll+0x3d8>
movl   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1512 <poll+0x3d2>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    14a1 <poll+0x361>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
jmp    14fc <poll+0x3bc>
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     14f7 <poll+0x3b7>
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    14fc <poll+0x3bc>
jmp    1501 <poll+0x3c1>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1466 <poll+0x326>
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
mov    %rsi,%r15
mov    %rdi,%rbx
test   %rdi,%rdi
jne    117a <poll+0x3a>
test   %r15,%r15
je     117a <poll+0x3a>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    0x2e32(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
jmp    13a3 <poll+0x263>
test   %edx,%edx
je     11a5 <poll+0x65>
jle    13b4 <poll+0x274>
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    11af <poll+0x6f>
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     1383 <poll+0x243>
mov    %rbp,0x20(%rsp)
lea    0x4(%rbx),%r12
mov    $0xffffffff,%ebp
mov    0x2d9c(%rip),%r13
mov    %r15,%r14
jmp    120e <poll+0xce>
nopl   0x0(%rax)
add    $0xc,%r12
add    $0xffffffffffffffff,%r14
je     12ff <poll+0x1bf>
mov    -0x4(%r12),%edi
test   %edi,%edi
js     1200 <poll+0xc0>
mov    (%r12),%eax
mov    0x2d9e(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d8d(%rip),%rdx
or     (%rdx),%ecx
test   %eax,%ecx
je     123f <poll+0xff>
lea    0x14(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    (%r12),%eax
mov    0x2d8a(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2da1(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d28(%rip),%rdx
or     (%rdx),%ecx
test   %eax,%ecx
je     1271 <poll+0x131>
mov    -0x4(%r12),%edi
lea    0x10(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    (%r12),%eax
mov    0x0(%r13),%ecx
mov    0x2d5c(%rip),%rdx
or     (%rdx),%ecx
test   %eax,%ecx
je     1291 <poll+0x151>
mov    -0x4(%r12),%edi
lea    0xc(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    -0x4(%r12),%eax
cmp    %ebp,%eax
jl     1200 <poll+0xc0>
mov    0x2d4b(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d0a(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d21(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d00(%rip),%rdx
or     (%rdx),%ecx
or     0x0(%r13),%ecx
mov    0x2d03(%rip),%rdx
or     (%rdx),%ecx
mov    0x2caa(%rip),%rdx
or     (%rdx),%ecx
test   %ecx,(%r12)
je     1200 <poll+0xc0>
mov    %eax,%ebp
mov    0x2cbd(%rip),%rcx
cmp    (%rcx),%eax
jle    1200 <poll+0xc0>
mov    0x2ce6(%rip),%rax
jmp    1165 <poll+0x25>
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     13a3 <poll+0x263>
test   %r15,%r15
je     13a3 <poll+0x263>
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
jmp    1360 <poll+0x220>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x0,(%rbx)
add    $0xc,%rbx
add    $0xffffffffffffffff,%r15
je     13a3 <poll+0x263>
mov    -0x8(%rbx),%edi
test   %edi,%edi
js     1350 <poll+0x210>
mov    -0x4(%rbx),%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <compute_revents@plt>
test   %eax,%eax
je     1356 <poll+0x216>
mov    %eax,(%rbx)
add    $0x1,%ebp
jmp    1356 <poll+0x216>
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
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xffffffff,%edx
je     13c5 <poll+0x285>
mov    0x2bd8(%rip),%rax
jmp    1165 <poll+0x25>
xor    %ebp,%ebp
jmp    11b8 <poll+0x78>

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

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