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

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int POLLERR;
int POLLIN;
int POLLOUT;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int working_poll(struct pollfd fds[], nfds_t nfds, int timeout) {
  fd_set readfds;
  fd_set writefds;
  fd_set errorfds;
  int maxfd = 0;
  int i, r;
  struct timeval tv = {timeout / 1000, (timeout % 1000) * 10};
  FD_ZERO(&readfds);
  FD_ZERO(&writefds);
  FD_ZERO(&errorfds);
  for (i = 0; i < nfds; ++i) {
    if (fds[i].fd + 1 > maxfd)
      maxfd = fds[i].fd + 1;
    if (fds[i].events & POLLIN) {
      FD_SET(fds[i].fd, &readfds);
    }
    if (fds[i].events & POLLOUT) {
      FD_SET(fds[i].fd, &writefds);
    }
  }
  r = select(maxfd, &readfds, &writefds, &errorfds, timeout != -1 ? &tv : NULL);
  if (r <= 0)
    return r;
  r = 0;
  for (i = 0; i < nfds; ++i) {
    fds[i].revents = 0;
    if (FD_ISSET(fds[i].fd, &readfds))
      fds[i].revents |= POLLIN;
    if (FD_ISSET(fds[i].fd, &writefds))
      fds[i].revents |= POLLOUT;
    if (FD_ISSET(fds[i].fd, &writefds))
      fds[i].revents |= POLLERR;
    if (fds[i].revents != 0)
      ++r;
  }
  return r;
}


x86 assembly (clang, -O0):
<working_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0xa,%edx,%eax
mov    %eax,-0x34(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <FD_ZERO@plt>
lea    -0x20(%rbp),%rdi
call   1040 <FD_ZERO@plt>
lea    -0x24(%rbp),%rdi
call   1040 <FD_ZERO@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1269 <working_poll+0x129>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x28(%rbp),%eax
jle    11da <working_poll+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2de5(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1218 <working_poll+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
mov    0x2dc7(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1256 <working_poll+0x116>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <FD_SET@plt>
jmp    125b <working_poll+0x11b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119a <working_poll+0x5a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     1286 <working_poll+0x146>
lea    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1291 <working_poll+0x151>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    1291 <working_poll+0x151>
mov    -0x3c(%rbp),%edi
mov    -0x48(%rbp),%r8
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1050 <select@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     12c1 <working_poll+0x181>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13f2 <working_poll+0x2b2>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    13ec <working_poll+0x2ac>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1333 <working_poll+0x1f3>
mov    0x2cbc(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1375 <working_poll+0x235>
mov    0x2c9a(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13b7 <working_poll+0x277>
mov    0x2c40(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rdx
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0x8(%rax)
je     13d9 <working_poll+0x299>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13de <working_poll+0x29e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12cf <working_poll+0x18f>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<working_poll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
movslq %edx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,0x20(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %eax,0x24(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <FD_ZERO@plt>
lea    0xc(%rsp),%rdi
call   1040 <FD_ZERO@plt>
lea    0x1c(%rsp),%rdi
call   1040 <FD_ZERO@plt>
mov    %ebp,%r14d
test   %ebp,%ebp
mov    %ebp,0x14(%rsp)
mov    %r15d,0x18(%rsp)
jle    121c <working_poll+0xdc>
lea    0x0(,%r14,4),%rax
lea    (%rax,%rax,2),%r15
xor    %r12d,%r12d
mov    0x2e32(%rip),%r13
xor    %ebp,%ebp
jmp    11d9 <working_poll+0x99>
nopw   0x0(%rax,%rax,1)
add    $0xc,%r12
cmp    %r12,%r15
je     121e <working_poll+0xde>
mov    %ebp,%ecx
mov    (%rbx,%r12,1),%edi
mov    0x4(%rbx,%r12,1),%eax
lea    0x1(%rdi),%ebp
cmp    %ecx,%edi
cmovl  %ecx,%ebp
mov    0x2de5(%rip),%rcx
test   %eax,(%rcx)
je     1206 <working_poll+0xc6>
lea    0x10(%rsp),%rsi
call   1060 <FD_SET@plt>
mov    0x4(%rbx,%r12,1),%eax
test   %eax,0x0(%r13)
je     11d0 <working_poll+0x90>
mov    (%rbx,%r12,1),%edi
lea    0xc(%rsp),%rsi
call   1060 <FD_SET@plt>
jmp    11d0 <working_poll+0x90>
xor    %ebp,%ebp
xor    %eax,%eax
cmpl   $0xffffffff,0x18(%rsp)
lea    0x20(%rsp),%r8
cmove  %rax,%r8
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x1c(%rsp),%rcx
mov    %ebp,%edi
call   1050 <select@plt>
mov    %eax,%ebp
sar    $0x1f,%ebp
and    %eax,%ebp
test   %eax,%eax
jle    12e8 <working_poll+0x1a8>
cmpl   $0x0,0x14(%rsp)
jle    12e8 <working_poll+0x1a8>
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r15
mov    0x2d63(%rip),%r13
jmp    129d <working_poll+0x15d>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%eax
mov    0x2d57(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rbx)
cmp    $0x1,%eax
sbb    $0xffffffff,%ebp
add    $0xc,%rbx
add    $0xffffffffffffffff,%r14
je     12e8 <working_poll+0x1a8>
movl   $0x0,(%rbx)
mov    -0x8(%rbx),%edi
mov    %r12,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12b9 <working_poll+0x179>
mov    0x0(%r13),%eax
or     %eax,(%rbx)
mov    -0x8(%rbx),%edi
mov    %r15,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12d4 <working_poll+0x194>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
or     %eax,(%rbx)
mov    -0x8(%rbx),%edi
mov    %r15,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    1280 <working_poll+0x140>
mov    (%rbx),%eax
jmp    128d <working_poll+0x14d>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
%struct.timeval = type { i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@POLLERR = global i32 0
define i32 @working_poll(%struct.pollfd* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.pollfd*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.timeval
store %struct.pollfd* %0, %struct.pollfd** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %11
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i32, i32* %7
%17 = sdiv i32 %16, 1000
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%19 = load i32, i32* %7
%20 = srem i32 %19, 1000
%21 = mul nsw i32 %20, 10
store i32 %21, i32* %18
%22 = call i32 @FD_ZERO(i32* %8)
%23 = call i32 @FD_ZERO(i32* %9)
%24 = call i32 @FD_ZERO(i32* %10)
store i32 0, i32* %12
br label %25
25: ; preds = %84, %3
%26 = load i32, i32* %12
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %87
29: ; preds = %25
%30 = load %struct.pollfd*, %struct.pollfd** %5
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i64 %32
%34 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %11
%38 = icmp sgt i32 %36, %37
br i1 %38, label %39, label %47
39: ; preds = %29
%40 = load %struct.pollfd*, %struct.pollfd** %5
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %40, i64 %42
%44 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %47
47: ; preds = %39, %29
%48 = load %struct.pollfd*, %struct.pollfd** %5
%49 = load i32, i32* %12
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %48, i64 %50
%52 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %51, i32 0, i32 1
%53 = load i32, i32* %52
%54 = load i32, i32* @POLLIN
%55 = and i32 %53, %54
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %47
%58 = load %struct.pollfd*, %struct.pollfd** %5
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %58, i64 %60
%62 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i32 @FD_SET(i32 %63, i32* %8)
br label %65
65: ; preds = %57, %47
%66 = load %struct.pollfd*, %struct.pollfd** %5
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %66, i64 %68
%70 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = load i32, i32* @POLLOUT
%73 = and i32 %71, %72
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %83
75: ; preds = %65
%76 = load %struct.pollfd*, %struct.pollfd** %5
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %76, i64 %78
%80 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i32 @FD_SET(i32 %81, i32* %9)
br label %83
83: ; preds = %75, %65
br label %84
84: ; preds = %83
%85 = load i32, i32* %12
%86 = add nsw i32 %85, 1
store i32 %86, i32* %12
br label %25
87: ; preds = %25
%88 = load i32, i32* %11
%89 = load i32, i32* %7
%90 = icmp ne i32 %89, -1
br i1 %90, label %91, label %92
91: ; preds = %87
br label %93
92: ; preds = %87
br label %93
93: ; preds = %92, %91
%94 = phi %struct.timeval* [ %14, %91 ], [ null, %92 ]
%95 = call i32 @select(i32 %88, i32* %8, i32* %9, i32* %10, %struct.timeval* %94)
store i32 %95, i32* %13
%96 = load i32, i32* %13
%97 = icmp sle i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %93
%99 = load i32, i32* %13
store i32 %99, i32* %4
br label %181
100: ; preds = %93
store i32 0, i32* %13
store i32 0, i32* %12
br label %101
101: ; preds = %176, %100
%102 = load i32, i32* %12
%103 = load i32, i32* %6
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %179
105: ; preds = %101
%106 = load %struct.pollfd*, %struct.pollfd** %5
%107 = load i32, i32* %12
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %106, i64 %108
%110 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %109, i32 0, i32 2
store i32 0, i32* %110
%111 = load %struct.pollfd*, %struct.pollfd** %5
%112 = load i32, i32* %12
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %111, i64 %113
%115 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %114, i32 0, i32 0
%116 = load i32, i32* %115
%117 = call i64 @FD_ISSET(i32 %116, i32* %8)
%118 = icmp ne i64 %117, 0
br i1 %118, label %119, label %128
119: ; preds = %105
%120 = load i32, i32* @POLLIN
%121 = load %struct.pollfd*, %struct.pollfd** %5
%122 = load i32, i32* %12
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %121, i64 %123
%125 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %124, i32 0, i32 2
%126 = load i32, i32* %125
%127 = or i32 %126, %120
store i32 %127, i32* %125
br label %128
128: ; preds = %119, %105
%129 = load %struct.pollfd*, %struct.pollfd** %5
%130 = load i32, i32* %12
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %129, i64 %131
%133 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %132, i32 0, i32 0
%134 = load i32, i32* %133
%135 = call i64 @FD_ISSET(i32 %134, i32* %9)
%136 = icmp ne i64 %135, 0
br i1 %136, label %137, label %146
137: ; preds = %128
%138 = load i32, i32* @POLLOUT
%139 = load %struct.pollfd*, %struct.pollfd** %5
%140 = load i32, i32* %12
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %139, i64 %141
%143 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %142, i32 0, i32 2
%144 = load i32, i32* %143
%145 = or i32 %144, %138
store i32 %145, i32* %143
br label %146
146: ; preds = %137, %128
%147 = load %struct.pollfd*, %struct.pollfd** %5
%148 = load i32, i32* %12
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %147, i64 %149
%151 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %150, i32 0, i32 0
%152 = load i32, i32* %151
%153 = call i64 @FD_ISSET(i32 %152, i32* %9)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %164
155: ; preds = %146
%156 = load i32, i32* @POLLERR
%157 = load %struct.pollfd*, %struct.pollfd** %5
%158 = load i32, i32* %12
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %157, i64 %159
%161 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %160, i32 0, i32 2
%162 = load i32, i32* %161
%163 = or i32 %162, %156
store i32 %163, i32* %161
br label %164
164: ; preds = %155, %146
%165 = load %struct.pollfd*, %struct.pollfd** %5
%166 = load i32, i32* %12
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %165, i64 %167
%169 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %168, i32 0, i32 2
%170 = load i32, i32* %169
%171 = icmp ne i32 %170, 0
br i1 %171, label %172, label %175
172: ; preds = %164
%173 = load i32, i32* %13
%174 = add nsw i32 %173, 1
store i32 %174, i32* %13
br label %175
175: ; preds = %172, %164
br label %176
176: ; preds = %175
%177 = load i32, i32* %12
%178 = add nsw i32 %177, 1
store i32 %178, i32* %12
br label %101
179: ; preds = %101
%180 = load i32, i32* %13
store i32 %180, i32* %4
br label %181
181: ; preds = %179, %98
%182 = load i32, i32* %4
ret i32 %182
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
%struct.timeval = type { i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@POLLERR = global i32 0
define i32 @working_poll(%struct.pollfd* nocapture %0, i32 %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 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%13 = sdiv i32 %2, 1000
store i32 %13, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%15 = srem i32 %2, 1000
%16 = mul nsw i32 %15, 10
store i32 %16, i32* %14
%17 = call i32 @FD_ZERO(i32* %4)
%18 = call i32 @FD_ZERO(i32* %5)
%19 = call i32 @FD_ZERO(i32* %6)
%20 = icmp sgt i32 %1, 0
br i1 %20, label %21, label %50
21: ; preds = %3
%22 = zext i32 %1 to i64
br label %23
23: ; preds = %21, %47
%24 = phi i64 [ 0, %21 ], [ %48, %47 ]
%25 = phi i32 [ 0, %21 ], [ %30, %47 ]
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %24, i32 0
%27 = load i32, i32* %26
%28 = icmp slt i32 %27, %25
%29 = add nsw i32 %27, 1
%30 = select i1 %28, i32 %25, i32 %29
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %24, i32 1
%32 = load i32, i32* %31
%33 = load i32, i32* @POLLIN
%34 = and i32 %33, %32
%35 = icmp eq i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %23
%37 = call i32 @FD_SET(i32 %27, i32* %4)
%38 = load i32, i32* %31
br label %39
39: ; preds = %36, %23
%40 = phi i32 [ %38, %36 ], [ %32, %23 ]
%41 = load i32, i32* @POLLOUT
%42 = and i32 %41, %40
%43 = icmp eq i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %39
%45 = load i32, i32* %26
%46 = call i32 @FD_SET(i32 %45, i32* %5)
br label %47
47: ; preds = %39, %44
%48 = add nuw nsw i64 %24, 1
%49 = icmp eq i64 %48, %22
br i1 %49, label %50, label %23
50: ; preds = %47, %3
%51 = phi i32 [ 0, %3 ], [ %30, %47 ]
%52 = icmp eq i32 %2, -1
%53 = select i1 %52, %struct.timeval* null, %struct.timeval* %7
%54 = call i32 @select(i32 %51, i32* %4, i32* %5, i32* %6, %struct.timeval* %53)
%55 = icmp slt i32 %54, 1
%56 = xor i1 %20, true
%57 = or i1 %55, %56
%58 = select i1 %55, i32 %54, i32 0
br i1 %57, label %98, label %59
59: ; preds = %50
%60 = zext i32 %1 to i64
br label %61
61: ; preds = %59, %91
%62 = phi i64 [ 0, %59 ], [ %96, %91 ]
%63 = phi i32 [ 0, %59 ], [ %95, %91 ]
%64 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %62, i32 2
store i32 0, i32* %64
%65 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %0, i64 %62, i32 0
%66 = load i32, i32* %65
%67 = call i64 @FD_ISSET(i32 %66, i32* %4)
%68 = icmp eq i64 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %61
%70 = load i32, i32* @POLLIN
%71 = load i32, i32* %64
%72 = or i32 %71, %70
store i32 %72, i32* %64
br label %73
73: ; preds = %69, %61
%74 = load i32, i32* %65
%75 = call i64 @FD_ISSET(i32 %74, i32* %5)
%76 = icmp eq i64 %75, 0
br i1 %76, label %81, label %77
77: ; preds = %73
%78 = load i32, i32* @POLLOUT
%79 = load i32, i32* %64
%80 = or i32 %79, %78
store i32 %80, i32* %64
br label %81
81: ; preds = %77, %73
%82 = load i32, i32* %65
%83 = call i64 @FD_ISSET(i32 %82, i32* %5)
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = load i32, i32* %64
br label %91
87: ; preds = %81
%88 = load i32, i32* @POLLERR
%89 = load i32, i32* %64
%90 = or i32 %89, %88
store i32 %90, i32* %64
br label %91
91: ; preds = %85, %87
%92 = phi i32 [ %86, %85 ], [ %90, %87 ]
%93 = icmp ne i32 %92, 0
%94 = zext i1 %93 to i32
%95 = add nuw nsw i32 %63, %94
%96 = add nuw nsw i64 %62, 1
%97 = icmp eq i64 %96, %60
br i1 %97, label %98, label %61
98: ; preds = %91, %50
%99 = phi i32 [ %58, %50 ], [ %95, %91 ]
ret i32 %99
}