#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 select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int select_nosignal(int max, fd_set *read, fd_set *write, fd_set *except,
                    struct timeval *tout) {
  int ret;
  errno = 0;
  while (1) {
    ret = select(max + 1, read, write, except, tout);
    if (ret >= 0 || (ret == -1 && errno != EINTR))
      break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<select_nosignal>:
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    0x2eae(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%edi
add    $0x1,%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)
cmpl   $0x0,-0x2c(%rbp)
jge    1185 <select_nosignal+0x75>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    118a <select_nosignal+0x7a>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
je     118a <select_nosignal+0x7a>
jmp    118f <select_nosignal+0x7f>
jmp    1139 <select_nosignal+0x29>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_nosignal>:
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    0x2eb0(%rip),%r13
movq   $0x0,0x0(%r13)
add    $0x1,%ebp
mov    %ebp,%edi
jmp    114e <select_nosignal+0x3e>
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <select@plt>
test   %eax,%eax
jns    1171 <select_nosignal+0x61>
cmp    $0xffffffff,%eax
jne    1140 <select_nosignal+0x30>
mov    0x0(%r13),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
je     1140 <select_nosignal+0x30>
mov    $0xffffffff,%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
define i32 @select_nosignal(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
store i64 0, i64* @errno
br label %12
12: ; preds = %5, %30
%13 = load i32, i32* %6
%14 = add nsw i32 %13, 1
%15 = load i32*, i32** %7
%16 = load i32*, i32** %8
%17 = load i32*, i32** %9
%18 = load %struct.timeval*, %struct.timeval** %10
%19 = call i32 @select(i32 %14, i32* %15, i32* %16, i32* %17, %struct.timeval* %18)
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = icmp sge i32 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %12
%23 = load i32, i32* %11
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25, %12
br label %31
30: ; preds = %25, %22
br label %12
31: ; preds = %29
%32 = load i32, i32* %11
ret i32 %32
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @select_nosignal(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %4) {
store i64 0, i64* @errno
%6 = add nsw i32 %0, 1
%7 = tail call i32 @select(i32 %6, i32* %1, i32* %2, i32* %3, %struct.timeval* %4)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %19, label %9
9: ; preds = %5, %16
%10 = phi i32 [ %17, %16 ], [ %7, %5 ]
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12, %9
%17 = tail call i32 @select(i32 %6, i32* %1, i32* %2, i32* %3, %struct.timeval* %4)
%18 = icmp sgt i32 %17, -1
br i1 %18, label %19, label %9
19: ; preds = %12, %16, %5
%20 = phi i32 [ %7, %5 ], [ %17, %16 ], [ -1, %12 ]
ret i32 %20
}