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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int I_wacom_wait_wacom(int fd) {
  struct timeval timeout;
  fd_set readfds;
  int err;
  FD_ZERO(&readfds);
  FD_SET(fd, &readfds);
  timeout.tv_sec = 0;
  timeout.tv_usec = 200000;
  err = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout);
  return ((err > 0) ? 1 : err);
}


x86 assembly (clang, -O0):
<I_wacom_wait_wacom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1050 <FD_SET@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x30d40,-0x18(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1196 <I_wacom_wait_wacom+0x66>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119c <I_wacom_wait_wacom+0x6c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@FD_SETSIZE = global i32 0
define i32 @I_wacom_wait_wacom(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 @FD_ZERO(i32* %4)
%7 = load i32, i32* %2
%8 = call i32 @FD_SET(i32 %7, i32* %4)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 200000, i32* %10
%11 = load i32, i32* @FD_SETSIZE
%12 = call i32 @select(i32 %11, i32* %4, i32* null, i32* null, %struct.timeval* %3)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
br label %18
16: ; preds = %1
%17 = load i32, i32* %5
br label %18
18: ; preds = %16, %15
%19 = phi i32 [ 1, %15 ], [ %17, %16 ]
ret i32 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@FD_SETSIZE = global i32 0
define i32 @I_wacom_wait_wacom(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @FD_ZERO(i32* %3)
%7 = call i32 @FD_SET(i32 %0, i32* %3)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 200000, i32* %9
%10 = load i32, i32* @FD_SETSIZE
%11 = call i32 @select(i32 %10, i32* %3, i32* null, i32* null, %struct.timeval* %2)
%12 = icmp slt i32 %11, 1
%13 = select i1 %12, i32 %11, i32 1
ret i32 %13
}