#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 */
int EINTR;
int errno;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int dss_select(int n, fd_set *readfds, fd_set *writefds,
               struct timeval *timeout_tv) {
  int ret, err;
  do {
    ret = select(n, readfds, writefds, NULL, timeout_tv);
    err = errno;
  } while (ret < 0 && err == EINTR);
  if (ret < 0)
    return -((errno) | (1 << 30));
  return ret;
}


x86 assembly (clang, -O0):
<dss_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <select@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x29(%rbp)
jge    116f <dss_select+0x5f>
mov    -0x28(%rbp),%eax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1127 <dss_select+0x17>
cmpl   $0x0,-0x24(%rbp)
jge    119f <dss_select+0x8f>
mov    0x2e55(%rip),%rax
mov    (%rax),%ecx
or     $0x40000000,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <dss_select+0x95>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dss_select>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb3(%rip),%r12
mov    0x2ea4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    %r14,%r8
call   1030 <select@plt>
mov    (%r12),%ecx
test   %eax,%eax
jns    1160 <dss_select+0x50>
cmp    0x0(%r13),%ecx
je     1140 <dss_select+0x30>
or     $0x40000000,%ecx
neg    %ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %ecx,%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 i32 0
@EINTR = global i32 0
define i32 @dss_select(i32 %0, i32* %1, i32* %2, %struct.timeval* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.timeval*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store %struct.timeval* %3, %struct.timeval** %9
br label %12
12: ; preds = %26, %4
%13 = load i32, i32* %6
%14 = load i32*, i32** %7
%15 = load i32*, i32** %8
%16 = load %struct.timeval*, %struct.timeval** %9
%17 = call i32 @select(i32 %13, i32* %14, i32* %15, i32* null, %struct.timeval* %16)
store i32 %17, i32* %10
%18 = load i32, i32* @errno
store i32 %18, i32* %11
br label %19
19: ; preds = %12
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %11
%24 = load i32, i32* @EINTR
%25 = icmp eq i32 %23, %24
br label %26
26: ; preds = %22, %19
%27 = phi i1 [ false, %19 ], [ %25, %22 ]
br i1 %27, label %12, label %28
28: ; preds = %26
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* @errno
%33 = or i32 %32, 1073741824
%34 = sub nsw i32 0, %33
store i32 %34, i32* %5
br label %37
35: ; preds = %28
%36 = load i32, i32* %10
store i32 %36, i32* %5
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i32 0
@EINTR = global i32 0
define i32 @dss_select(i32 %0, i32* %1, i32* %2, %struct.timeval* %3) {
br label %5
5: ; preds = %5, %4
%6 = tail call i32 @select(i32 %0, i32* %1, i32* %2, i32* null, %struct.timeval* %3)
%7 = load i32, i32* @errno
%8 = icmp slt i32 %6, 0
%9 = load i32, i32* @EINTR
%10 = icmp eq i32 %7, %9
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %5, label %12
12: ; preds = %5
%13 = or i32 %7, 1073741824
%14 = sub nsw i32 0, %13
%15 = select i1 %8, i32 %14, i32 %6
ret i32 %15
}