#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 */
typedef int /*<<< orphan*/ uint32_t;
struct timeval {
  int /*<<< orphan*/ tv_sec;
  scalar_t__ tv_usec;
};
typedef scalar_t__ int32_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ select(scalar_t__, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
int /*<<< orphan*/ wait_interval(int /*<<< orphan*/);
void wait_interval_fd(int32_t fd, uint32_t seconds) {
  if (fd > 0) {
    struct timeval tv;
    tv.tv_usec = 0;
    tv.tv_sec = seconds;
    fd_set set;
    FD_ZERO(&set);
    FD_SET(fd, &set);
    select(fd + 1, &set, NULL, NULL, &tv);
  } else {
    wait_interval(seconds);
  }
}


x86 assembly (clang, -O0):
<wait_interval_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jle    119f <wait_interval_fd+0x5f>
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x8(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
jmp    11a7 <wait_interval_fd+0x67>
mov    -0xc(%rbp),%edi
call   1030 <wait_interval@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_interval_fd>:
test   %rdi,%rdi
jle    1194 <wait_interval_fd+0x54>
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
mov    %esi,0x8(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
add    $0x1,%rbx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    %esi,%edi
jmp    1030 <wait_interval@plt>

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @wait_interval_fd(i64 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = icmp sgt i64 %0, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = bitcast %struct.timeval* %3 to i8*
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %1, i32* %9
%10 = bitcast i32* %4 to i8*
%11 = call i32 @FD_ZERO(i32* %4)
%12 = call i32 @FD_SET(i64 %0, i32* %4)
%13 = add nuw nsw i64 %0, 1
%14 = call i32 @select(i64 %13, i32* %4, i32* null, i32* null, %struct.timeval* %3)
br label %17
15: ; preds = %2
%16 = tail call i32 @wait_interval(i32 %1)
br label %17
17: ; preds = %15, %6
ret void
}