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

/* Variables and functions */
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int _error(char const *, char *, int);
int /*<<< orphan*/ printf(char *, char const *, char *);
scalar_t__ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *, struct timeval *);
int _select(char const *progname) {
  fd_set rfds;
  fd_set wfds;
  fd_set efds;
  struct timeval timeout;
  printf("%s: Testing %s()\n", progname, "select");
  FD_ZERO(&rfds);
  FD_ZERO(&wfds);
  FD_ZERO(&efds);
  timeout.tv_sec = 0;
  timeout.tv_usec = 0;
  if (select(0, &rfds, &wfds, &efds, &timeout) != 0)
    return _error(progname, "select", 2);
  return 0;
}


x86 assembly (clang, -O0):
<_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
lea    0xeb4(%rip),%rdx
call   1030 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1040 <FD_ZERO@plt>
lea    -0x18(%rbp),%rdi
call   1040 <FD_ZERO@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <FD_ZERO@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1050 <select@plt>
cmp    $0x0,%rax
je     11cc <_select+0x8c>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x2,%edx
call   1060 <_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11d3 <_select+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_select>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r12
lea    0xeaa(%rip),%rdi
lea    0xeb5(%rip),%rdx
mov    %r12,%rsi
call   1030 <printf@plt>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1040 <FD_ZERO@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
xor    %ebp,%ebp
lea    0x10(%rsp),%r8
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <select@plt>
test   %rax,%rax
je     11c6 <_select+0x86>
lea    0xe5b(%rip),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1060 <_error@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [18 x i8] c"%s: Testing %s()\0A\00"
@.str.1 = [7 x i8] c"select\00"
define i32 @_select(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @FD_ZERO(i32* %4)
%11 = call i32 @FD_ZERO(i32* %5)
%12 = call i32 @FD_ZERO(i32* %6)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i64 0, i64* %14
%15 = call i64 @select(i32 0, i32* %4, i32* %5, i32* %6, %struct.timeval* %7)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @_error(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %19, i32* %2
br label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [18 x i8] c"%s: Testing %s()\0A\00"
@.str.1 = [7 x i8] c"select\00"
define i32 @_select(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.timeval* %5 to i8*
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @FD_ZERO(i32* %2)
%12 = call i32 @FD_ZERO(i32* %3)
%13 = call i32 @FD_ZERO(i32* %4)
%14 = bitcast %struct.timeval* %5 to i8*
%15 = call i64 @select(i32 0, i32* %2, i32* %3, i32* %4, %struct.timeval* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %1
%18 = call i32 @_error(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %19
19: ; preds = %1, %17
%20 = phi i32 [ %18, %17 ], [ 0, %1 ]
ret i32 %20
}