#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;
  int /*<<< orphan*/ tv_sec;
};
struct timespec {
  int tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int __libc_pselect6(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *, struct timespec *,
                    int /*<<< orphan*/);
int __libc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
                  struct timeval *timeout) {
  struct timespec _ts, *ts = 0;
  if (timeout) {
    _ts.tv_sec = timeout->tv_sec;
    _ts.tv_nsec = timeout->tv_usec * 1000;
    ts = &_ts;
  }
  return __libc_pselect6(n, readfds, writefds, exceptfds, ts, 0);
}


x86 assembly (clang, -O0):
<__libc_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     115d <__libc_select+0x4d>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
imul   $0x3e8,(%rax),%eax
mov    %eax,-0x30(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
xor    %r9d,%r9d
call   1030 <__libc_pselect6@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__libc_select>:
push   %rax
test   %r8,%r8
je     112d <__libc_select+0x1d>
mov    0x4(%r8),%eax
mov    %eax,0x4(%rsp)
imul   $0x3e8,(%r8),%eax
mov    %eax,(%rsp)
mov    %rsp,%r8
jmp    1130 <__libc_select+0x20>
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <__libc_pselect6@plt>
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i32, i32 }
define i32 @__libc_select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca %struct.timeval*
%11 = alloca %struct.timespec
%12 = alloca %struct.timespec*
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store %struct.timeval* %4, %struct.timeval** %10
store %struct.timespec* null, %struct.timespec** %12
%13 = load %struct.timeval*, %struct.timeval** %10
%14 = icmp ne %struct.timeval* %13, null
br i1 %14, label %15, label %25
15: ; preds = %5
%16 = load %struct.timeval*, %struct.timeval** %10
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
store i32 %18, i32* %19
%20 = load %struct.timeval*, %struct.timeval** %10
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = mul nsw i32 %22, 1000
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
store i32 %23, i32* %24
store %struct.timespec* %11, %struct.timespec** %12
br label %25
25: ; preds = %15, %5
%26 = load i32, i32* %6
%27 = load i32*, i32** %7
%28 = load i32*, i32** %8
%29 = load i32*, i32** %9
%30 = load %struct.timespec*, %struct.timespec** %12
%31 = call i32 @__libc_pselect6(i32 %26, i32* %27, i32* %28, i32* %29, %struct.timespec* %30, i32 0)
ret i32 %31
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i32, i32 }
define i32 @__libc_select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4) {
%6 = alloca %struct.timespec
%7 = bitcast %struct.timespec* %6 to i8*
%8 = icmp eq %struct.timeval* %4, null
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, 1000
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
store i32 %15, i32* %16
br label %17
17: ; preds = %9, %5
%18 = phi %struct.timespec* [ %6, %9 ], [ null, %5 ]
%19 = call i32 @__libc_pselect6(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timespec* %18, i32 0)
ret i32 %19
}