#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 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 & (0x0001 | 0x0040))
      FD_SET(pfd[i].fd, &rfds);
    if (pfd[i].events & (0x0004 | 0x0100 | 0x0200))
      FD_SET(pfd[i].fd, &wfds);
    if (pfd[i].events & (0x0002 | 0x0080))
      FD_SET(pfd[i].fd, &efds);
    if (pfd[i].fd >= maxfd &&
        (pfd[i].events &
         (0x0001 | 0x0004 | 0x0002 | 0x0040 | 0x0080 | 0x0100 | 0x0200))) {
      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++;
      } else {
        pfd[i].revents = 0;
      }
    }
  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    0x2e4f(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14bc <poll+0x37c>
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    0x2dad(%rip),%rax
mov    (%rax),%ecx
mov    0x2dac(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14bc <poll+0x37c>
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    13b0 <poll+0x270>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    1286 <poll+0x146>
jmp    139f <poll+0x25f>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
and    $0x41,%eax
cmp    $0x0,%eax
je     12b8 <poll+0x178>
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
and    $0x304,%eax
cmp    $0x0,%eax
je     12ec <poll+0x1ac>
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
and    $0x82,%eax
cmp    $0x0,%eax
je     1320 <poll+0x1e0>
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     139a <poll+0x25a>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
and    $0x3c7,%eax
cmp    $0x0,%eax
je     139a <poll+0x25a>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2c61(%rip),%rcx
cmp    (%rcx),%eax
jle    1395 <poll+0x255>
mov    0x2c6a(%rip),%rax
mov    (%rax),%ecx
mov    0x2c41(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14bc <poll+0x37c>
jmp    139a <poll+0x25a>
jmp    139f <poll+0x25f>
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    13e3 <poll+0x2a3>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14bc <poll+0x37c>
movl   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    14b6 <poll+0x376>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
cmpl   $0x0,(%rax)
jge    142d <poll+0x2ed>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
jmp    14a0 <poll+0x360>
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     1488 <poll+0x348>
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    149b <poll+0x35b>
mov    -0x10(%rbp),%rax
imul   $0xc,-0x48(%rbp),%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
jmp    14a0 <poll+0x360>
jmp    14a5 <poll+0x365>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    13f2 <poll+0x2b2>
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    0x2e5a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
jmp    1323 <poll+0x1e3>
test   %edx,%edx
je     11a5 <poll+0x65>
jle    1334 <poll+0x1f4>
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     1303 <poll+0x1c3>
mov    %rbp,0x20(%rsp)
lea    0x4(%rbx),%r12
mov    $0xffffffff,%ebp
lea    0x14(%rsp),%r13
mov    %r15,%r14
jmp    120a <poll+0xca>
nopw   0x0(%rax,%rax,1)
add    $0xc,%r12
add    $0xffffffffffffffff,%r14
je     1283 <poll+0x143>
mov    -0x4(%r12),%edi
test   %edi,%edi
js     1200 <poll+0xc0>
mov    (%r12),%eax
test   $0x41,%al
je     1227 <poll+0xe7>
mov    %r13,%rsi
call   1060 <FD_SET@plt>
mov    (%r12),%eax
test   $0x304,%eax
je     1241 <poll+0x101>
mov    -0x4(%r12),%edi
lea    0x10(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    (%r12),%eax
test   $0x82,%al
je     1254 <poll+0x114>
mov    -0x4(%r12),%edi
lea    0xc(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    -0x4(%r12),%eax
cmp    %ebp,%eax
jl     1200 <poll+0xc0>
movzwl (%r12),%ecx
test   $0x3c7,%ecx
je     1200 <poll+0xc0>
mov    %eax,%ebp
mov    0x2d5d(%rip),%rcx
cmp    (%rcx),%eax
jle    1200 <poll+0xc0>
mov    0x2d6a(%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     1323 <poll+0x1e3>
test   %r15,%r15
je     1323 <poll+0x1e3>
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
jmp    12e0 <poll+0x1a0>
nopl   0x0(%rax,%rax,1)
movl   $0x0,(%rbx)
add    $0xc,%rbx
add    $0xffffffffffffffff,%r15
je     1323 <poll+0x1e3>
mov    -0x8(%rbx),%edi
test   %edi,%edi
js     12d0 <poll+0x190>
mov    -0x4(%rbx),%esi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <compute_revents@plt>
test   %eax,%eax
je     12d0 <poll+0x190>
mov    %eax,(%rbx)
add    $0x1,%ebp
jmp    12d6 <poll+0x196>
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     1345 <poll+0x205>
mov    0x2c80(%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
@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 %206
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 %206
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 = %143, %53
%58 = load i64, i64* %15
%59 = load i64, i64* %6
%60 = icmp ult i64 %58, %59
br i1 %60, label %61, label %146
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 %143
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 = and i32 %74, 65
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %69
%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, %69
%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 = and i32 %89, 772
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %99
92: ; preds = %84
%93 = load %struct.pollfd*, %struct.pollfd** %5
%94 = load i64, i64* %15
%95 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %93, i64 %94
%96 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %95, i32 0, i32 0
%97 = load i32, i32* %96
%98 = call i32 @FD_SET(i32 %97, i32* %9)
br label %99
99: ; preds = %92, %84
%100 = load %struct.pollfd*, %struct.pollfd** %5
%101 = load i64, i64* %15
%102 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %100, i64 %101
%103 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %102, i32 0, i32 1
%104 = load i32, i32* %103
%105 = and i32 %104, 130
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %114
107: ; preds = %99
%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 0
%112 = load i32, i32* %111
%113 = call i32 @FD_SET(i32 %112, i32* %10)
br label %114
114: ; preds = %107, %99
%115 = load %struct.pollfd*, %struct.pollfd** %5
%116 = load i64, i64* %15
%117 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %115, i64 %116
%118 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %117, i32 0, i32 0
%119 = load i32, i32* %118
%120 = load i32, i32* %13
%121 = icmp sge i32 %119, %120
br i1 %121, label %122, label %142
122: ; preds = %114
%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 1
%127 = load i32, i32* %126
%128 = and i32 %127, 967
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %142
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 0
%135 = load i32, i32* %134
store i32 %135, i32* %13
%136 = load i32, i32* %13
%137 = load i32, i32* @FD_SETSIZE
%138 = icmp sgt i32 %136, %137
br i1 %138, label %139, label %141
139: ; preds = %130
%140 = load i32, i32* @EOVERFLOW
store i32 %140, i32* @errno
store i32 -1, i32* %4
br label %206
141: ; preds = %130
br label %142
142: ; preds = %141, %122, %114
br label %143
143: ; preds = %142, %68
%144 = load i64, i64* %15
%145 = add i64 %144, 1
store i64 %145, i64* %15
br label %57
146: ; preds = %57
%147 = load i32, i32* %13
%148 = add nsw i32 %147, 1
%149 = load %struct.timeval*, %struct.timeval** %12
%150 = call i32 @select(i32 %148, i32* %8, i32* %9, i32* %10, %struct.timeval* %149)
store i32 %150, i32* %14
%151 = load i32, i32* %14
%152 = icmp slt i32 %151, 0
br i1 %152, label %153, label %155
153: ; preds = %146
%154 = load i32, i32* %14
store i32 %154, i32* %4
br label %206
155: ; preds = %146
store i32 0, i32* %14
store i64 0, i64* %15
br label %156
156: ; preds = %201, %155
%157 = load i64, i64* %15
%158 = load i64, i64* %6
%159 = icmp ult i64 %157, %158
br i1 %159, label %160, label %204
160: ; preds = %156
%161 = load %struct.pollfd*, %struct.pollfd** %5
%162 = load i64, i64* %15
%163 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %161, i64 %162
%164 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %163, i32 0, i32 0
%165 = load i32, i32* %164
%166 = icmp slt i32 %165, 0
br i1 %166, label %167, label %172
167: ; preds = %160
%168 = load %struct.pollfd*, %struct.pollfd** %5
%169 = load i64, i64* %15
%170 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %168, i64 %169
%171 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %170, i32 0, i32 2
store i32 0, i32* %171
br label %200
172: ; preds = %160
%173 = load %struct.pollfd*, %struct.pollfd** %5
%174 = load i64, i64* %15
%175 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %173, i64 %174
%176 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %175, i32 0, i32 0
%177 = load i32, i32* %176
%178 = load %struct.pollfd*, %struct.pollfd** %5
%179 = load i64, i64* %15
%180 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %178, i64 %179
%181 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %180, i32 0, i32 1
%182 = load i32, i32* %181
%183 = call i32 @compute_revents(i32 %177, i32 %182, i32* %8, i32* %9, i32* %10)
store i32 %183, i32* %16
%184 = load i32, i32* %16
%185 = icmp ne i32 %184, 0
br i1 %185, label %186, label %194
186: ; preds = %172
%187 = load i32, i32* %16
%188 = load %struct.pollfd*, %struct.pollfd** %5
%189 = load i64, i64* %15
%190 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %188, i64 %189
%191 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %190, i32 0, i32 2
store i32 %187, i32* %191
%192 = load i32, i32* %14
%193 = add nsw i32 %192, 1
store i32 %193, i32* %14
br label %199
194: ; preds = %172
%195 = load %struct.pollfd*, %struct.pollfd** %5
%196 = load i64, i64* %15
%197 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %195, i64 %196
%198 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %197, i32 0, i32 2
store i32 0, i32* %198
br label %199
199: ; preds = %194, %186
br label %200
200: ; preds = %199, %167
br label %201
201: ; preds = %200
%202 = load i64, i64* %15
%203 = add i64 %202, 1
store i64 %203, i64* %15
br label %156
204: ; preds = %156
%205 = load i32, i32* %14
store i32 %205, i32* %4
br label %206
206: ; preds = %204, %153, %139, %49, %22
%207 = load i32, i32* %4
ret i32 %207
}

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
@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 %111, 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 %111
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 %86, label %37
37: ; preds = %31, %76
%38 = phi i64 [ %78, %76 ], [ 0, %31 ]
%39 = phi i32 [ %77, %76 ], [ -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 %76, label %43
43: ; preds = %37
%44 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %38, i32 1
%45 = load i32, i32* %44
%46 = and i32 %45, 65
%47 = icmp eq i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %43
%49 = call i32 @FD_SET(i32 %41, i32* %4)
%50 = load i32, i32* %44
br label %51
51: ; preds = %48, %43
%52 = phi i32 [ %50, %48 ], [ %45, %43 ]
%53 = and i32 %52, 772
%54 = icmp eq i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = load i32, i32* %40
%57 = call i32 @FD_SET(i32 %56, i32* %5)
%58 = load i32, i32* %44
br label %59
59: ; preds = %55, %51
%60 = phi i32 [ %58, %55 ], [ %52, %51 ]
%61 = and i32 %60, 130
%62 = icmp eq i32 %61, 0
br i1 %62, label %66, label %63
63: ; preds = %59
%64 = load i32, i32* %40
%65 = call i32 @FD_SET(i32 %64, i32* %6)
br label %66
66: ; preds = %63, %59
%67 = load i32, i32* %40
%68 = icmp slt i32 %67, %39
br i1 %68, label %76, label %69
69: ; preds = %66
%70 = load i32, i32* %44
%71 = and i32 %70, 967
%72 = icmp eq i32 %71, 0
br i1 %72, label %76, label %73
73: ; preds = %69
%74 = load i32, i32* @FD_SETSIZE
%75 = icmp sgt i32 %67, %74
br i1 %75, label %111, label %76
76: ; preds = %66, %69, %73, %37
%77 = phi i32 [ %39, %37 ], [ %67, %73 ], [ %39, %69 ], [ %39, %66 ]
%78 = add nuw i64 %38, 1
%79 = icmp eq i64 %78, %1
br i1 %79, label %80, label %37
80: ; preds = %76
%81 = add nsw i32 %77, 1
%82 = call i32 @select(i32 %81, i32* %4, i32* %5, i32* %6, %struct.timeval* %32)
%83 = icmp slt i32 %82, 0
%84 = or i1 %83, %36
%85 = select i1 %83, i32 %82, i32 0
br i1 %84, label %114, label %90
86: ; preds = %31
%87 = call i32 @select(i32 0, i32* %4, i32* %5, i32* %6, %struct.timeval* %32)
%88 = icmp slt i32 %87, 0
%89 = select i1 %88, i32 %87, i32 0
br label %114
90: ; preds = %80, %107
%91 = phi i64 [ %109, %107 ], [ 0, %80 ]
%92 = phi i32 [ %108, %107 ], [ 0, %80 ]
%93 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %91, i32 0
%94 = load i32, i32* %93
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %90
%97 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %91, i32 2
store i32 0, i32* %97
br label %107
98: ; preds = %90
%99 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %91, i32 1
%100 = load i32, i32* %99
%101 = call i32 @compute_revents(i32 %94, i32 %100, i32* %4, i32* %5, i32* %6)
%102 = icmp eq i32 %101, 0
%103 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %91, i32 2
br i1 %102, label %106, label %104
104: ; preds = %98
store i32 %101, i32* %103
%105 = add nsw i32 %92, 1
br label %107
106: ; preds = %98
store i32 0, i32* %103
br label %107
107: ; preds = %104, %106, %96
%108 = phi i32 [ %92, %96 ], [ %105, %104 ], [ %92, %106 ]
%109 = add nuw i64 %91, 1
%110 = icmp eq i64 %109, %1
br i1 %110, label %114, label %90
111: ; preds = %73, %26, %3
%112 = phi i32* [ @EFAULT, %3 ], [ @EINVAL, %26 ], [ @EOVERFLOW, %73 ]
%113 = load i32, i32* %112
store i32 %113, i32* @errno
br label %114
114: ; preds = %107, %86, %111, %80
%115 = phi i32 [ %85, %80 ], [ %89, %86 ], [ -1, %111 ], [ %108, %107 ]
ret i32 %115
}