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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int FD_SETSIZE;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  long to_sec = 4;
  int selectfds[] = {0, 1, 2};
  fd_set readfds;
  int ready, nfds, flags;
  struct timeval timeout;
  struct timeval *pto;
  char ch;
  int fd, i;
  pto = &timeout;
  timeout.tv_sec = to_sec;
  timeout.tv_usec = 0;
  nfds = 0;
  for (i = 0; i < 3; ++i) {
    int fd = selectfds[i];
    if (fd >= FD_SETSIZE)
      do {
        fprintf(stderr, "fd exceeds limit"
                        "\n");
        _exit(1);
      } while (0);
    if (fd >= nfds)
      nfds = fd + 1;
    FD_SET(fd, &readfds);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x4,-0x18(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xea9(%rip),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x3,-0x5c(%rbp)
jge    1202 <main+0xd2>
movslq -0x5c(%rbp),%rax
mov    -0x24(%rbp,%rax,4),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jl     11d3 <main+0xa3>
jmp    11b4 <main+0x84>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x60(%rbp),%eax
cmp    -0x30(%rbp),%eax
jl     11e8 <main+0xb8>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x60(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1188 <main+0x58>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rbx
cmpl   $0x0,(%rbx)
jle    117d <main+0x4d>
lea    0xc(%rsp),%rsi
xor    %edi,%edi
call   1050 <FD_SET@plt>
cmpl   $0x2,(%rbx)
jl     117d <main+0x4d>
lea    0xc(%rsp),%rsi
mov    $0x1,%edi
call   1050 <FD_SET@plt>
cmpl   $0x3,(%rbx)
jl     117d <main+0x4d>
lea    0xc(%rsp),%rsi
mov    $0x2,%edi
call   1050 <FD_SET@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@__const.main.selectfds = [3 x i32] [i32 0, i32 1, i32 2]
@FD_SETSIZE = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"fd exceeds limit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [3 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval*
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4, i64* %6
%18 = bitcast [3 x i32]* %7 to i8*
store %struct.timeval* %12, %struct.timeval** %13
%19 = load i64, i64* %6
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i64 %19, i64* %20
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %21
store i32 0, i32* %10
store i32 0, i32* %16
br label %22
22: ; preds = %49, %2
%23 = load i32, i32* %16
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %52
25: ; preds = %22
%26 = load i32, i32* %16
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %27
%29 = load i32, i32* %28
store i32 %29, i32* %17
%30 = load i32, i32* %17
%31 = load i32, i32* @FD_SETSIZE
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %25
br label %34
34: ; preds = %33
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @_exit(i32 1)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %25
%40 = load i32, i32* %17
%41 = load i32, i32* %10
%42 = icmp sge i32 %40, %41
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* %17
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %46
46: ; preds = %43, %39
%47 = load i32, i32* %17
%48 = call i32 @FD_SET(i32 %47, i32* %8)
br label %49
49: ; preds = %46
%50 = load i32, i32* %16
%51 = add nsw i32 %50, 1
store i32 %51, i32* %16
br label %22
52: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@FD_SETSIZE = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"fd exceeds limit\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @FD_SETSIZE
%6 = icmp sgt i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %15, %11, %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @_exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i32 @FD_SET(i32 0, i32* %3)
%13 = load i32, i32* @FD_SETSIZE
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %7
15: ; preds = %11
%16 = call i32 @FD_SET(i32 1, i32* %3)
%17 = load i32, i32* @FD_SETSIZE
%18 = icmp sgt i32 %17, 2
br i1 %18, label %19, label %7
19: ; preds = %15
%20 = call i32 @FD_SET(i32 2, i32* %3)
ret i32 0
}