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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int htxd_select(int socket_fd) {
  int result;
  fd_set read_fd_set;
  struct timeval timeout;
  FD_ZERO(&read_fd_set);
  timeout.tv_sec = 100;
  timeout.tv_usec = 0;
  FD_SET(socket_fd, &read_fd_set);
  result = select(socket_fd + 1, &read_fd_set, NULL, NULL, &timeout);
  if ((result == -1) && (errno != EINTR)) {
    perror("ERROR: while selecting connection. Exiting...");
    exit(1);
  }
  return result;
}


x86 assembly (clang, -O0):
<htxd_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <FD_ZERO@plt>
movl   $0x64,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1070 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11d6 <htxd_select+0x86>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%rax
je     11d6 <htxd_select+0x86>
lea    0xe39(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htxd_select>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
movl   $0x64,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <FD_SET@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
cmp    $0xffffffff,%eax
jne    11b2 <htxd_select+0x62>
mov    0x2e3d(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e2b(%rip),%rdx
cmp    (%rdx),%rcx
jne    11ba <htxd_select+0x6a>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe3f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [46 x i8] c"ERROR: while selecting connection. Exiting...\00"
define i32 @htxd_select(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
store i32 %0, i32* %2
%6 = call i32 @FD_ZERO(i32* %4)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 100, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 0, i64* %8
%9 = load i32, i32* %2
%10 = call i32 @FD_SET(i32 %9, i32* %4)
%11 = load i32, i32* %2
%12 = add nsw i32 %11, 1
%13 = call i32 @select(i32 %12, i32* %4, i32* null, i32* null, %struct.timeval* %5)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %1
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16, %1
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [46 x i8] c"ERROR: while selecting connection. Exiting...\00"
define i32 @htxd_select(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @FD_ZERO(i32* %2)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 100, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %8
%9 = call i32 @FD_SET(i32 %0, i32* %2)
%10 = add nsw i32 %0, 1
%11 = call i32 @select(i32 %10, i32* %2, i32* null, i32* null, %struct.timeval* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13, %1
ret i32 %11
}