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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int std_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
               struct timeval *timeout) {
  int numfd;
std_select_begin:
  if ((numfd = select(nfds, readfds, writefds, exceptfds, timeout)) == -1) {
    if (errno == EINTR)
      goto std_select_begin;
    perror("select");
    exit(1);
  }
  return numfd;
}


x86 assembly (clang, -O0):
<std_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <select@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11a4 <std_select+0x74>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <std_select+0x5e>
jmp    114b <std_select+0x1b>
lea    0xe6b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<std_select>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e88(%rip),%r13
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <select@plt>
cmp    $0xffffffff,%eax
jne    118e <std_select+0x5e>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
je     1150 <std_select+0x20>
lea    0xe81(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
define i32 @std_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 i32
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
br label %12
12: ; preds = %24, %5
%13 = load i32, i32* %6
%14 = load i32*, i32** %7
%15 = load i32*, i32** %8
%16 = load i32*, i32** %9
%17 = load %struct.timeval*, %struct.timeval** %10
%18 = call i32 @select(i32 %13, i32* %14, i32* %15, i32* %16, %struct.timeval* %17)
store i32 %18, i32* %11
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %28
20: ; preds = %12
%21 = load i64, i64* @errno
%22 = load i64, i64* @EINTR
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
br label %12
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %12
%29 = load i32, i32* %11
ret i32 %29
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
define i32 @std_select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4) {
br label %6
6: ; preds = %9, %5
%7 = tail call i32 @select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br i1 %12, label %6, label %13
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %6
ret i32 %7
}