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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int fileno(int /*<<< orphan*/ *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
int fpoll(void *h) {
  FILE *f = (FILE *)h;
  fd_set x;
  struct timeval timeout;
  timeout.tv_sec = 1;
  timeout.tv_usec = 0;
  int fd = fileno(f);
  FD_ZERO(&x);
  FD_SET(fd, &x);
  int r = select(fd + 1, &x, 0, 0, &timeout);
  return r;
}


x86 assembly (clang, -O0):
<fpoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fileno@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x2c(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
mov    %ecx,%edx
call   1050 <select@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fpoll>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x1,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1030 <fileno@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i32 @fpoll(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %3
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 1, i32* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 0, i64* %11
%12 = load i32*, i32** %3
%13 = call i32 @fileno(i32* %12)
store i32 %13, i32* %6
%14 = call i32 @FD_ZERO(i32* %4)
%15 = load i32, i32* %6
%16 = call i32 @FD_SET(i32 %15, i32* %4)
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = call i32 @select(i32 %18, i32* %4, i32 0, i32 0, %struct.timeval* %5)
store i32 %19, i32* %7
%20 = load i32, i32* %7
ret i32 %20
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @fpoll(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = bitcast i8* %0 to i32*
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 1, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %8
%9 = tail call i32 @fileno(i32* %4)
%10 = call i32 @FD_ZERO(i32* %2)
%11 = call i32 @FD_SET(i32 %9, i32* %2)
%12 = add nsw i32 %9, 1
%13 = call i32 @select(i32 %12, i32* %2, i32 0, i32 0, %struct.timeval* %3)
ret i32 %13
}