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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
double trunc(double);
int wait_fd_seconds(int fd, double seconds) {
  struct timeval tv;
  fd_set in_fds;
  FD_ZERO(&in_fds);
  FD_SET(fd, &in_fds);
  tv.tv_sec = trunc(seconds);
  tv.tv_usec = (seconds - trunc(seconds)) * 1e6;
  return select(fd + 1, &in_fds, 0, 0, &tv);
}


x86 assembly (clang, -O0):
<wait_fd_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1060 <FD_SET@plt>
movsd  -0x10(%rbp),%xmm0
call   1050 <trunc@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <trunc@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe64(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x24(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x20(%rbp),%r8
mov    %ecx,%edx
call   1040 <select@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_fd_seconds>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %edi,%ebx
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
movsd  0x8(%rsp),%xmm0
call   1050 <trunc@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe77(%rip),%xmm1
movsd  %xmm1,0x20(%rsp)
add    $0x1,%ebx
lea    0x18(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
define i32 @wait_fd_seconds(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca %struct.timeval
%6 = alloca i32
store i32 %0, i32* %3
store double %1, double* %4
%7 = call i32 @FD_ZERO(i32* %6)
%8 = load i32, i32* %3
%9 = call i32 @FD_SET(i32 %8, i32* %6)
%10 = load double, double* %4
%11 = call double @llvm.trunc.f64(double %10)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store double %11, double* %12
%13 = load double, double* %4
%14 = load double, double* %4
%15 = call double @llvm.trunc.f64(double %14)
%16 = fsub double %13, %15
%17 = fmul double %16, 1.000000e+06
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store double %17, double* %18
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
%21 = call i32 @select(i32 %20, i32* %6, i32 0, i32 0, %struct.timeval* %5)
ret i32 %21
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
define i32 @wait_fd_seconds(i32 %0, double %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @FD_ZERO(i32* %4)
%8 = call i32 @FD_SET(i32 %0, i32* %4)
%9 = call double @llvm.trunc.f64(double %1)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store double %9, double* %10
%11 = fsub double %1, %9
%12 = fmul double %11, 1.000000e+06
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store double %12, double* %13
%14 = add nsw i32 %0, 1
%15 = call i32 @select(i32 %14, i32* %4, i32 0, i32 0, %struct.timeval* %3)
ret i32 %15
}