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

/* Variables and functions */
int FD_ISSET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ STDIN_FILENO;
int /*<<< orphan*/ printf(char *, ...);
int select(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void select_test(void) {
  int ret;
  fd_set read;
  struct timeval tim;
  FD_ZERO(&read);
  FD_SET(STDIN_FILENO, &read);
  tim.tv_sec = 5;
  tim.tv_usec = 0;
  printf("Select...\n");
  ret = select(STDIN_FILENO + 1, &read, NULL, NULL, &tim);
  printf("ret: %d\n", ret);
  printf("is_set: %d\n", FD_ISSET(STDIN_FILENO, &read));
}


x86 assembly (clang, -O0):
<select_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <FD_SET@plt>
movl   $0x5,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1060 <select@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <FD_ISSET@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_test>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <FD_ZERO@plt>
mov    0x2e65(%rip),%r14
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1080 <FD_SET@plt>
movl   $0x5,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%rdi
add    $0x1,%rdi
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <select@plt>
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@STDIN_FILENO = global i64 0
@.str = [11 x i8] c"Select...\0A\00"
@.str.1 = [9 x i8] c"ret: %d\0A\00"
@.str.2 = [12 x i8] c"is_set: %d\0A\00"
define void @select_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = call i32 @FD_ZERO(i32* %2)
%5 = load i64, i64* @STDIN_FILENO
%6 = call i32 @FD_SET(i64 %5, i32* %2)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 5, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 0, i64* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = load i64, i64* @STDIN_FILENO
%11 = add nsw i64 %10, 1
%12 = call i32 @select(i64 %11, i32* %2, i32* null, i32* null, %struct.timeval* %3)
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i64, i64* @STDIN_FILENO
%16 = call i32 @FD_ISSET(i64 %15, i32* %2)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@STDIN_FILENO = global i64 0
@.str.1 = [9 x i8] c"ret: %d\0A\00"
@.str.2 = [12 x i8] c"is_set: %d\0A\00"
@str = [10 x i8] c"Select...\00"
define void @select_test() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @FD_ZERO(i32* %1)
%6 = load i64, i64* @STDIN_FILENO
%7 = call i32 @FD_SET(i64 %6, i32* %1)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 5, i32* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 0, i64* %9
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%11 = load i64, i64* @STDIN_FILENO
%12 = add nsw i64 %11, 1
%13 = call i32 @select(i64 %12, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i64, i64* @STDIN_FILENO
%16 = call i32 @FD_ISSET(i64 %15, i32* %1)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}