#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;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int os_pollfd(int fd, int maxus) {
  fd_set rfds;
  struct timeval tv;
  if (maxus >= 1000000) {
    tv.tv_sec = maxus / 1000000;
    tv.tv_usec = maxus % 1000000;
  } else {
    tv.tv_sec = 0;
    tv.tv_usec = maxus;
  }
  FD_ZERO(&rfds);
  FD_SET(fd, &rfds);
  return select(fd + 1, &rfds, NULL, NULL, &tv) > 0;
}


x86 assembly (clang, -O0):
<os_pollfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jl     116c <os_pollfd+0x3c>
mov    -0x8(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
jmp    1179 <os_pollfd+0x49>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
cmp    $0x0,%rax
setg   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_pollfd>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
xor    %eax,%eax
cmp    $0xf4240,%esi
jl     1158 <os_pollfd+0x28>
mov    %esi,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
imul   $0xf4240,%eax,%ecx
sub    %ecx,%esi
mov    %eax,0x8(%rsp)
mov    %esi,0xc(%rsp)
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <FD_SET@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
xor    %ecx,%ecx
test   %rax,%rax
setg   %cl
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @os_pollfd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 1000000
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* %4
%14 = srem i32 %13, 1000000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i32 %14, i32* %15
br label %20
16: ; preds = %2
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 0, i32* %17
%18 = load i32, i32* %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i32 %18, i32* %19
br label %20
20: ; preds = %16, %9
%21 = call i32 @FD_ZERO(i32* %5)
%22 = load i32, i32* %3
%23 = call i32 @FD_SET(i32 %22, i32* %5)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = call i64 @select(i32 %25, i32* %5, i32* null, i32* null, %struct.timeval* %6)
%27 = icmp sgt i64 %26, 0
%28 = zext i1 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @os_pollfd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp sgt i32 %1, 999999
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = udiv i32 %1, 1000000
%10 = urem i32 %1, 1000000
br label %11
11: ; preds = %2, %8
%12 = phi i32 [ %9, %8 ], [ 0, %2 ]
%13 = phi i32 [ %10, %8 ], [ %1, %2 ]
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %12, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i32 %13, i32* %15
%16 = call i32 @FD_ZERO(i32* %3)
%17 = call i32 @FD_SET(i32 %0, i32* %3)
%18 = add nsw i32 %0, 1
%19 = call i64 @select(i32 %18, i32* %3, i32* null, i32* null, %struct.timeval* %4)
%20 = icmp sgt i64 %19, 0
%21 = zext i1 %20 to i32
ret i32 %21
}