#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 {
  long tv_sec;
  long tv_usec;
};
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 my_select(int fd, fd_set *fdread, fd_set *fdwrite, fd_set *fdex, long sec,
              long usec) {
  int ret_val;
  struct timeval stv;
  fd_set *fdr2, *fdw2, *fde2;
  do {
    fdr2 = fdread;
    fdw2 = fdwrite;
    fde2 = fdex;
    stv.tv_sec = sec;
    stv.tv_usec = usec;
    ret_val = select(fd, fdr2, fdw2, fde2, &stv);
  } while (ret_val == -1 && errno == EINTR);
  return ret_val;
}


x86 assembly (clang, -O0):
<my_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x60(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1030 <select@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x34(%rbp)
mov    %al,-0x61(%rbp)
jne    119b <my_select+0x8b>
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    112f <my_select+0x1f>
mov    -0x34(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_select>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
nop
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
lea    0x8(%rsp),%r8
call   1030 <select@plt>
cmp    $0xffffffff,%eax
jne    116a <my_select+0x5a>
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e7b(%rip),%rdx
cmp    %rcx,(%rdx)
je     1130 <my_select+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @my_select(i32 %0, i32* %1, i32* %2, i32* %3, i64 %4, i64 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i64 %4, i64* %11
store i64 %5, i64* %12
br label %18
18: ; preds = %38, %6
%19 = load i32*, i32** %8
store i32* %19, i32** %15
%20 = load i32*, i32** %9
store i32* %20, i32** %16
%21 = load i32*, i32** %10
store i32* %21, i32** %17
%22 = load i64, i64* %11
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i64 %22, i64* %23
%24 = load i64, i64* %12
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
store i64 %24, i64* %25
%26 = load i32, i32* %7
%27 = load i32*, i32** %15
%28 = load i32*, i32** %16
%29 = load i32*, i32** %17
%30 = call i32 @select(i32 %26, i32* %27, i32* %28, i32* %29, %struct.timeval* %14)
store i32 %30, i32* %13
br label %31
31: ; preds = %18
%32 = load i32, i32* %13
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i64, i64* @errno
%36 = load i64, i64* @EINTR
%37 = icmp eq i64 %35, %36
br label %38
38: ; preds = %34, %31
%39 = phi i1 [ false, %31 ], [ %37, %34 ]
br i1 %39, label %18, label %40
40: ; preds = %38
%41 = load i32, i32* %13
ret i32 %41
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @my_select(i32 %0, i32* %1, i32* %2, i32* %3, i64 %4, i64 %5) {
%7 = alloca %struct.timeval
%8 = bitcast %struct.timeval* %7 to i8*
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
br label %11
11: ; preds = %11, %6
store i64 %4, i64* %9
store i64 %5, i64* %10
%12 = call i32 @select(i32 %0, i32* %1, i32* %2, i32* %3, %struct.timeval* %7)
%13 = icmp eq i32 %12, -1
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
%17 = select i1 %13, i1 %16, i1 false
br i1 %17, label %11, label %18
18: ; preds = %11
ret i32 %12
}