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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int errno;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int xnet_select(int s, int sec, int usec, short x) {
  int st = errno;
  struct timeval to;
  fd_set fs;
  to.tv_sec = sec;
  to.tv_usec = usec;
  FD_ZERO(&fs);
  FD_SET(s, &fs);
  switch (x) {
  case 0:
    st = select(s + 1, &fs, 0, 0, &to);
    break;
  case 1:
    st = select(s + 1, 0, &fs, 0, &to);
    break;
  case 2:
    st = select(s + 1, 0, 0, &fs, &to);
    break;
  }
  return (st);
}


x86 assembly (clang, -O0):
<xnet_select>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cx,%ax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x24(%rbp),%rdi
mov    %rdi,-0x30(%rbp)
call   1030 <FD_ZERO@plt>
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   1050 <FD_SET@plt>
movswl -0xe(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     11af <xnet_select+0x7f>
jmp    118d <xnet_select+0x5d>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
je     11d1 <xnet_select+0xa1>
jmp    119e <xnet_select+0x6e>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     11f3 <xnet_select+0xc3>
jmp    1210 <xnet_select+0xe0>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
mov    %eax,-0x14(%rbp)
jmp    1210 <xnet_select+0xe0>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x24(%rbp),%rdx
lea    -0x20(%rbp),%r8
mov    %rcx,%rsi
call   1040 <select@plt>
mov    %eax,-0x14(%rbp)
jmp    1210 <xnet_select+0xe0>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x24(%rbp),%rcx
lea    -0x20(%rbp),%r8
mov    %rdx,%rsi
call   1040 <select@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xnet_select>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %edi,%ebx
mov    0x2e9b(%rip),%rax
mov    (%rax),%r14d
mov    %esi,0x10(%rsp)
mov    %edx,0x14(%rsp)
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1050 <FD_SET@plt>
cmp    $0x2,%ebp
je     1188 <xnet_select+0x58>
cmp    $0x1,%ebp
je     119d <xnet_select+0x6d>
test   %ebp,%ebp
jne    11b8 <xnet_select+0x88>
add    $0x1,%ebx
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%r8
mov    %ebx,%edi
xor    %edx,%edx
jmp    11ae <xnet_select+0x7e>
add    $0x1,%ebx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
jmp    11b0 <xnet_select+0x80>
add    $0x1,%ebx
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <select@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@errno = global i32 0
define i32 @xnet_select(i32 %0, i32 %1, i32 %2, i16 signext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca i32
%10 = alloca %struct.timeval
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i16 %3, i16* %8
%12 = load i32, i32* @errno
store i32 %12, i32* %9
%13 = load i32, i32* %6
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* %7
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i32 %15, i32* %16
%17 = call i32 @FD_ZERO(i32* %11)
%18 = load i32, i32* %5
%19 = call i32 @FD_SET(i32 %18, i32* %11)
%20 = load i16, i16* %8
%21 = sext i16 %20 to i32
switch i32 %21, label %34 [
i32 0, label %22
i32 1, label %26
i32 2, label %30
]
22: ; preds = %4
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
%25 = call i32 @select(i32 %24, i32* %11, i32* null, i32* null, %struct.timeval* %10)
store i32 %25, i32* %9
br label %34
26: ; preds = %4
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
%29 = call i32 @select(i32 %28, i32* null, i32* %11, i32* null, %struct.timeval* %10)
store i32 %29, i32* %9
br label %34
30: ; preds = %4
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
%33 = call i32 @select(i32 %32, i32* null, i32* null, i32* %11, %struct.timeval* %10)
store i32 %33, i32* %9
br label %34
34: ; preds = %4, %30, %26, %22
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@errno = global i32 0
define i32 @xnet_select(i32 %0, i32 %1, i32 %2, i16 signext %3) {
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = load i32, i32* @errno
%8 = bitcast %struct.timeval* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 %1, i32* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i32 %2, i32* %11
%12 = call i32 @FD_ZERO(i32* %6)
%13 = call i32 @FD_SET(i32 %0, i32* %6)
%14 = sext i16 %3 to i32
switch i32 %14, label %24 [
i32 0, label %15
i32 1, label %18
i32 2, label %21
]
15: ; preds = %4
%16 = add nsw i32 %0, 1
%17 = call i32 @select(i32 %16, i32* %6, i32* null, i32* null, %struct.timeval* %5)
br label %24
18: ; preds = %4
%19 = add nsw i32 %0, 1
%20 = call i32 @select(i32 %19, i32* null, i32* %6, i32* null, %struct.timeval* %5)
br label %24
21: ; preds = %4
%22 = add nsw i32 %0, 1
%23 = call i32 @select(i32 %22, i32* null, i32* null, i32* %6, %struct.timeval* %5)
br label %24
24: ; preds = %4, %21, %18, %15
%25 = phi i32 [ %7, %4 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ]
ret i32 %25
}