#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*/ printf(char *, scalar_t__);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int select_w(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
             struct timeval *timeout) {
  int ret;
repeat_select:
  ret = select(nfds, readfds, writefds, exceptfds, timeout);
  if (ret < 0) {
    if (errno == EINTR) {
      goto repeat_select;
    }
    printf("select error errno=%d \n", errno);
  }
  return ret;
}


x86 assembly (clang, -O0):
<select_w>:
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   1040 <select@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1195 <select_w+0x75>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    117f <select_w+0x5f>
jmp    113b <select_w+0x1b>
mov    0x2e5a(%rip),%rax
mov    (%rax),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_w>:
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,%r13
mov    %edi,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <select@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117b <select_w+0x5b>
mov    0x2e80(%rip),%rax
mov    (%rax),%rsi
mov    0x2e6e(%rip),%rax
cmp    (%rax),%rsi
je     1140 <select_w+0x20>
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
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 = [24 x i8] c"select error errno=%d \0A\00"
define i32 @select_w(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 = %25, %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 = load i32, i32* %11
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %12
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINTR
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %12
26: ; preds = %21
%27 = load i64, i64* @errno
%28 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %26, %12
%30 = load i32, i32* %11
ret i32 %30
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [24 x i8] c"select error errno=%d \0A\00"
define i32 @select_w(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 slt i32 %7, 0
br i1 %8, label %9, label %15
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 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %15
15: ; preds = %6, %13
ret i32 %7
}