#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 pollfd {
  int events;
  int revents;
  int /*<<< orphan*/ fd;
};

/* Variables and functions */
int POLLIN;
int POLLPRI;
int POLLRDBAND;
int POLLRDNORM;
int /*<<< orphan*/ STDIN_FILENO;
int poll(struct pollfd *, int, int /*<<< orphan*/);
int _kbhit(void) {
  struct pollfd pfds[1];
  pfds[0].fd = STDIN_FILENO;
  pfds[0].events = POLLIN | POLLPRI | POLLRDBAND | POLLRDNORM;
  return (poll(pfds, 1, 0) == 1) &&
         (pfds[0].revents & (POLLIN | POLLPRI | POLLRDBAND | POLLRDNORM));
}


x86 assembly (clang, -O0):
<_kbhit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    0x2ebc(%rip),%rcx
or     (%rcx),%eax
mov    0x2e8b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e9a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <poll@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x11(%rbp)
jne    119d <_kbhit+0x8d>
mov    -0xc(%rbp),%eax
mov    0x2e63(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e72(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e41(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e50(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_kbhit>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    0x2eab(%rip),%r14
mov    0x2ebc(%rip),%r15
mov    (%r15),%ecx
or     (%r14),%ecx
mov    %eax,0x8(%rsp)
mov    0x2e83(%rip),%r12
or     (%r12),%ecx
mov    0x2e90(%rip),%r13
or     0x0(%r13),%ecx
mov    %ecx,(%rsp)
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <poll@plt>
cmp    $0x1,%eax
jne    1184 <_kbhit+0x74>
mov    (%r15),%eax
or     (%r14),%eax
or     (%r12),%eax
or     0x0(%r13),%eax
xor    %ebx,%ebx
test   %eax,0x4(%rsp)
setne  %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@POLLPRI = global i32 0
@POLLRDBAND = global i32 0
@POLLRDNORM = global i32 0
define i32 @_kbhit() {
%1 = alloca [1 x %struct.pollfd]
%2 = load i32, i32* @STDIN_FILENO
%3 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0
%4 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %3, i32 0, i32 2
store i32 %2, i32* %4
%5 = load i32, i32* @POLLIN
%6 = load i32, i32* @POLLPRI
%7 = or i32 %5, %6
%8 = load i32, i32* @POLLRDBAND
%9 = or i32 %7, %8
%10 = load i32, i32* @POLLRDNORM
%11 = or i32 %9, %10
%12 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0
%13 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0
%15 = call i32 @poll(%struct.pollfd* %14, i32 1, i32 0)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %30
17: ; preds = %0
%18 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0
%19 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load i32, i32* @POLLIN
%22 = load i32, i32* @POLLPRI
%23 = or i32 %21, %22
%24 = load i32, i32* @POLLRDBAND
%25 = or i32 %23, %24
%26 = load i32, i32* @POLLRDNORM
%27 = or i32 %25, %26
%28 = and i32 %20, %27
%29 = icmp ne i32 %28, 0
br label %30
30: ; preds = %17, %0
%31 = phi i1 [ false, %0 ], [ %29, %17 ]
%32 = zext i1 %31 to i32
ret i32 %32
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@POLLPRI = global i32 0
@POLLRDBAND = global i32 0
@POLLRDNORM = global i32 0
define i32 @_kbhit() {
%1 = alloca [1 x %struct.pollfd]
%2 = bitcast [1 x %struct.pollfd]* %1 to i8*
%3 = load i32, i32* @STDIN_FILENO
%4 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0, i32 2
store i32 %3, i32* %5
%6 = load i32, i32* @POLLIN
%7 = load i32, i32* @POLLPRI
%8 = or i32 %7, %6
%9 = load i32, i32* @POLLRDBAND
%10 = or i32 %8, %9
%11 = load i32, i32* @POLLRDNORM
%12 = or i32 %10, %11
%13 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0, i32 0
store i32 %12, i32* %13
%14 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 0)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %29
16: ; preds = %0
%17 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0, i32 1
%18 = load i32, i32* %17
%19 = load i32, i32* @POLLIN
%20 = load i32, i32* @POLLPRI
%21 = or i32 %20, %19
%22 = load i32, i32* @POLLRDBAND
%23 = or i32 %21, %22
%24 = load i32, i32* @POLLRDNORM
%25 = or i32 %23, %24
%26 = and i32 %25, %18
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %16, %0
%30 = phi i32 [ 0, %0 ], [ %28, %16 ]
ret i32 %30
}