#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__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ open_pipe(int *, char const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
scalar_t__ strcmp(char *, char const *);
int main(int argc, char *argv[]) {
  fd_set rfds, wfds;
  const int count = 4;
  int fds[count], i;
  char buff[100];
  int retval;
  struct timeval tv;
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  if (2 != argc ||
      (0 != strcmp("read", argv[1]) && 0 != strcmp("write", argv[1]))) {
    printf("usage: ./select_test read|write\n");
    return -1;
  }
  const char *op = argv[1];
  const char *pipes[] = {
      "/dev/scullp_sz0",
      "/dev/scullp_sz1",
      "/dev/scullp_sz2",
      "/dev/scullp_sz3",
  };
  for (i = 0; i < count; i++) {
    open_pipe(fds + i, pipes[i]);
  }
  if (0 == strcmp("read", op)) {
    FD_ZERO(&rfds);
    for (i = 0; i < count; i++) {
      FD_SET(fds[i], &rfds);
    }
    retval = select(fds[count - 1] + 1, &rfds, NULL, NULL, &tv);
  } else {
    FD_ZERO(&wfds);
    for (i = 0; i < count; i++) {
      FD_SET(fds[i], &wfds);
    }
    retval = select(fds[count - 1] + 1, NULL, &wfds, NULL, &tv);
  }
  if (-1 == retval) {
    printf("select error\n");
    return -1;
  } else if (retval) {
    if (0 == strcmp("read", op)) {
      for (i = 0; i < count; i++) {
        if (FD_ISSET(fds[i], &rfds)) {
          printf("%s is readable\n", pipes[i]);
          memset(buff, 0, 100);
          read(fds[i], buff, 100);
          printf("%s\n", buff);
        }
      }
    } else {
      for (i = 0; i < count; i++) {
        if (FD_ISSET(fds[i], &wfds)) {
          printf("%s is writable\n", pipes[i]);
        }
      }
    }
  } else {
    if (0 == strcmp("read", op)) {
      printf("No data within ten seconds\n");
    } else {
      printf("Can not write within ten seconds\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
movl   $0xa,-0xa8(%rbp)
movq   $0x0,-0xa0(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    121e <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe17(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1242 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdfa(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1242 <main+0xb2>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xac(%rbp)
jmp    1580 <main+0x3f0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2ba8(%rip),%rax
mov    %rax,-0xe0(%rbp)
mov    0x2ba2(%rip),%rax
mov    %rax,-0xd8(%rbp)
mov    0x2b9c(%rip),%rax
mov    %rax,-0xd0(%rbp)
mov    0x2b96(%rip),%rax
mov    %rax,-0xc8(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    12cb <main+0x13b>
movslq -0x2c(%rbp),%rax
lea    -0xf0(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
movslq -0x2c(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rsi
ff
call   10a0 <open_pipe@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1290 <main+0x100>
mov    -0xb8(%rbp),%rsi
lea    0xd27(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1353 <main+0x1c3>
lea    -0x14(%rbp),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    1328 <main+0x198>
movslq -0x2c(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edi
lea    -0x14(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12fc <main+0x16c>
mov    -0xe4(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xa8(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x94(%rbp)
jmp    13b5 <main+0x225>
lea    -0x18(%rbp),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    138f <main+0x1ff>
movslq -0x2c(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1363 <main+0x1d3>
mov    -0xe4(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%rdx
lea    -0xa8(%rbp),%r8
mov    %rcx,%rsi
call   1090 <select@plt>
mov    %eax,-0x94(%rbp)
mov    $0xffffffff,%eax
cmp    -0x94(%rbp),%eax
jne    13ea <main+0x25a>
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xac(%rbp)
jmp    1580 <main+0x3f0>
cmpl   $0x0,-0x94(%rbp)
je     1523 <main+0x393>
mov    -0xb8(%rbp),%rsi
lea    0xbfb(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    14bd <main+0x32d>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    14b8 <main+0x328>
movslq -0x2c(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edi
lea    -0x14(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14a5 <main+0x315>
movslq -0x2c(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rsi
ff
lea    0xc20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
movslq -0x2c(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
lea    -0x90(%rbp),%rsi
lea    0xbec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14aa <main+0x31a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    141f <main+0x28f>
jmp    151e <main+0x38e>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    1519 <main+0x389>
movslq -0x2c(%rbp),%rax
mov    -0xf0(%rbp,%rax,4),%edi
lea    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1506 <main+0x376>
movslq -0x2c(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rsi
ff
lea    0xb8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    150b <main+0x37b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14c4 <main+0x334>
jmp    151e <main+0x38e>
jmp    156a <main+0x3da>
mov    -0xb8(%rbp),%rsi
lea    0xacf(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1557 <main+0x3c7>
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1565 <main+0x3d5>
lea    0xb5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    156a <main+0x3da>
jmp    156f <main+0x3df>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xac(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rsp,%r15
movl   $0xa,0x20(%rsp)
movq   $0x0,0x28(%rsp)
cmp    $0x2,%edi
jne    11f2 <main+0x52>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0xe2d(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1215 <main+0x75>
mov    0x8(%rbx),%rsi
lea    0xee0(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1215 <main+0x75>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %r15,%rsp
mov    %ebx,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rbx),%r14
lea    0xde5(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <open_pipe@plt>
lea    0x4(%rsp),%rdi
lea    0xde1(%rip),%rsi
call   10b0 <open_pipe@plt>
lea    0x8(%rsp),%rdi
lea    0xde0(%rip),%rsi
call   10b0 <open_pipe@plt>
lea    0xc(%rsp),%rdi
lea    0xddf(%rip),%rsi
call   10b0 <open_pipe@plt>
lea    0xd9e(%rip),%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12be <main+0x11e>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <FD_ZERO@plt>
mov    (%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0xc(%rsp),%edi
add    $0x1,%edi
lea    0x20(%rsp),%r8
xor    %esi,%esi
mov    %rbx,%rdx
jmp    130b <main+0x16b>
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <FD_ZERO@plt>
mov    (%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0xc(%rsp),%edi
add    $0x1,%edi
lea    0x20(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   10a0 <select@plt>
test   %eax,%eax
je     1327 <main+0x187>
cmp    $0xffffffff,%eax
jne    134b <main+0x1ab>
lea    0xd7f(%rip),%rdi
jmp    11f9 <main+0x59>
lea    0xcd2(%rip),%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1409 <main+0x269>
lea    0xd1f(%rip),%rdi
jmp    1410 <main+0x270>
lea    0xcae(%rip),%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
mov    (%rsp),%edi
test   %rax,%rax
je     141c <main+0x27c>
lea    0x18(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     138a <main+0x1ea>
lea    0xcd9(%rip),%rdi
lea    0xc82(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
lea    0x18(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     13b2 <main+0x212>
lea    0xcb1(%rip),%rdi
lea    0xc6a(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
lea    0x18(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     13da <main+0x23a>
lea    0xc89(%rip),%rdi
lea    0xc52(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
lea    0x18(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1415 <main+0x275>
lea    0xc61(%rip),%rdi
lea    0xc3a(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1203 <main+0x63>
lea    0xc76(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1203 <main+0x63>
lea    0x1c(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     146c <main+0x2cc>
lea    0xc13(%rip),%rdi
lea    0xbcc(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
lea    0x1c(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     14c1 <main+0x321>
lea    0xbbf(%rip),%rdi
lea    0xb88(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x1c(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1516 <main+0x376>
lea    0xb6a(%rip),%rdi
lea    0xb43(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0x1c(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1415 <main+0x275>
lea    0xb11(%rip),%rdi
lea    0xafa(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1203 <main+0x63>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [5 x i8] c"read\00"
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [33 x i8] c"usage: ./select_test read|write\0A\00"
@.str.3 = [16 x i8] c"/dev/scullp_sz0\00"
@.str.4 = [16 x i8] c"/dev/scullp_sz1\00"
@.str.5 = [16 x i8] c"/dev/scullp_sz2\00"
@.str.6 = [16 x i8] c"/dev/scullp_sz3\00"
@__const.main.pipes = [4 x i8*] [i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0)]
@.str.7 = [14 x i8] c"select error\0A\00"
@.str.8 = [16 x i8] c"%s is readable\0A\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@.str.10 = [16 x i8] c"%s is writable\0A\00"
@.str.11 = [28 x i8] c"No data within ten seconds\0A\00"
@.str.12 = [34 x i8] c"Can not write within ten seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [100 x i8]
%12 = alloca i32
%13 = alloca %struct.timeval
%14 = alloca i32
%15 = alloca i8*
%16 = alloca [4 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %8
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i32, i64 4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 10, i32* %19
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %20
%21 = load i32, i32* %4
%22 = icmp ne i32 2, %21
br i1 %22, label %35, label %23
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = icmp ne i64 0, %27
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = icmp ne i64 0, %33
br i1 %34, label %35, label %37
35: ; preds = %29, %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %14
br label %177
37: ; preds = %29, %23
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
store i8* %40, i8** %15
%41 = bitcast [4 x i8*]* %16 to i8*
store i32 0, i32* %10
br label %42
42: ; preds = %54, %37
%43 = load i32, i32* %10
%44 = icmp slt i32 %43, 4
br i1 %44, label %45, label %57
45: ; preds = %42
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %18, i64 %47
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [4 x i8*], [4 x i8*]* %16, i64 0, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 @open_pipe(i32* %48, i8* %52)
br label %54
54: ; preds = %45
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %42
57: ; preds = %42
%58 = load i8*, i8** %15
%59 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %58)
%60 = icmp eq i64 0, %59
br i1 %60, label %61, label %80
61: ; preds = %57
%62 = call i32 @FD_ZERO(i32* %6)
store i32 0, i32* %10
br label %63
63: ; preds = %72, %61
%64 = load i32, i32* %10
%65 = icmp slt i32 %64, 4
br i1 %65, label %66, label %75
66: ; preds = %63
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %18, i64 %68
%70 = load i32, i32* %69
%71 = call i32 @FD_SET(i32 %70, i32* %6)
br label %72
72: ; preds = %66
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %63
75: ; preds = %63
%76 = getelementptr inbounds i32, i32* %18, i64 3
%77 = load i32, i32* %76
%78 = add nsw i32 %77, 1
%79 = call i32 @select(i32 %78, i32* %6, i32* null, i32* null, %struct.timeval* %13)
store i32 %79, i32* %12
br label %99
80: ; preds = %57
%81 = call i32 @FD_ZERO(i32* %7)
store i32 0, i32* %10
br label %82
82: ; preds = %91, %80
%83 = load i32, i32* %10
%84 = icmp slt i32 %83, 4
br i1 %84, label %85, label %94
85: ; preds = %82
%86 = load i32, i32* %10
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %18, i64 %87
%89 = load i32, i32* %88
%90 = call i32 @FD_SET(i32 %89, i32* %7)
br label %91
91: ; preds = %85
%92 = load i32, i32* %10
%93 = add nsw i32 %92, 1
store i32 %93, i32* %10
br label %82
94: ; preds = %82
%95 = getelementptr inbounds i32, i32* %18, i64 3
%96 = load i32, i32* %95
%97 = add nsw i32 %96, 1
%98 = call i32 @select(i32 %97, i32* null, i32* %7, i32* null, %struct.timeval* %13)
store i32 %98, i32* %12
br label %99
99: ; preds = %94, %75
%100 = load i32, i32* %12
%101 = icmp eq i32 -1, %100
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %14
br label %177
104: ; preds = %99
%105 = load i32, i32* %12
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %166
107: ; preds = %104
%108 = load i8*, i8** %15
%109 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %108)
%110 = icmp eq i64 0, %109
br i1 %110, label %111, label %143
111: ; preds = %107
store i32 0, i32* %10
br label %112
112: ; preds = %139, %111
%113 = load i32, i32* %10
%114 = icmp slt i32 %113, 4
br i1 %114, label %115, label %142
115: ; preds = %112
%116 = load i32, i32* %10
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i32, i32* %18, i64 %117
%119 = load i32, i32* %118
%120 = call i64 @FD_ISSET(i32 %119, i32* %6)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %138
122: ; preds = %115
%123 = load i32, i32* %10
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [4 x i8*], [4 x i8*]* %16, i64 0, i64 %124
%126 = load i8*, i8** %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %126)
%128 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%129 = call i32 @memset(i8* %128, i32 0, i32 100)
%130 = load i32, i32* %10
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i32, i32* %18, i64 %131
%133 = load i32, i32* %132
%134 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%135 = call i32 @read(i32 %133, i8* %134, i32 100)
%136 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %136)
br label %138
138: ; preds = %122, %115
br label %139
139: ; preds = %138
%140 = load i32, i32* %10
%141 = add nsw i32 %140, 1
store i32 %141, i32* %10
br label %112
142: ; preds = %112
br label %165
143: ; preds = %107
store i32 0, i32* %10
br label %144
144: ; preds = %161, %143
%145 = load i32, i32* %10
%146 = icmp slt i32 %145, 4
br i1 %146, label %147, label %164
147: ; preds = %144
%148 = load i32, i32* %10
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i32, i32* %18, i64 %149
%151 = load i32, i32* %150
%152 = call i64 @FD_ISSET(i32 %151, i32* %7)
%153 = icmp ne i64 %152, 0
br i1 %153, label %154, label %160
154: ; preds = %147
%155 = load i32, i32* %10
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [4 x i8*], [4 x i8*]* %16, i64 0, i64 %156
%158 = load i8*, i8** %157
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* %158)
br label %160
160: ; preds = %154, %147
br label %161
161: ; preds = %160
%162 = load i32, i32* %10
%163 = add nsw i32 %162, 1
store i32 %163, i32* %10
br label %144
164: ; preds = %144
br label %165
165: ; preds = %164, %142
br label %175
166: ; preds = %104
%167 = load i8*, i8** %15
%168 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %167)
%169 = icmp eq i64 0, %168
br i1 %169, label %170, label %172
170: ; preds = %166
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0))
br label %174
172: ; preds = %166
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0))
br label %174
174: ; preds = %172, %170
br label %175
175: ; preds = %174, %165
br label %176
176: ; preds = %175
store i32 0, i32* %3
store i32 1, i32* %14
br label %177
177: ; preds = %176, %102, %35
%178 = load i8*, i8** %9
%179 = load i32, i32* %3
ret i32 %179
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [5 x i8] c"read\00"
@.str.1 = [6 x i8] c"write\00"
@.str.3 = [16 x i8] c"/dev/scullp_sz0\00"
@.str.4 = [16 x i8] c"/dev/scullp_sz1\00"
@.str.5 = [16 x i8] c"/dev/scullp_sz2\00"
@.str.6 = [16 x i8] c"/dev/scullp_sz3\00"
@.str.8 = [16 x i8] c"%s is readable\0A\00"
@.str.10 = [16 x i8] c"%s is writable\0A\00"
@str = [33 x i8] c"Can not write within ten seconds\00"
@str.13 = [27 x i8] c"No data within ten seconds\00"
@str.14 = [13 x i8] c"select error\00"
@str.15 = [32 x i8] c"usage: ./select_test read|write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca %struct.timeval
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i8* @llvm.stacksave()
%10 = alloca [4 x i32]
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = bitcast %struct.timeval* %6 to i8*
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
store i32 10, i32* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
store i64 0, i64* %14
%15 = icmp eq i32 %0, 2
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = load i8*, i8** %17
%23 = tail call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21, %2
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.15, i64 0, i64 0))
br label %142
27: ; preds = %21, %16
%28 = load i8*, i8** %17
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%30 = call i32 @open_pipe(i32* %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 1
%32 = call i32 @open_pipe(i32* %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 2
%34 = call i32 @open_pipe(i32* %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 3
%36 = call i32 @open_pipe(i32* %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%37 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %28)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %27
%40 = call i32 @FD_ZERO(i32* %3)
%41 = load i32, i32* %29
%42 = call i32 @FD_SET(i32 %41, i32* %3)
%43 = load i32, i32* %31
%44 = call i32 @FD_SET(i32 %43, i32* %3)
%45 = load i32, i32* %33
%46 = call i32 @FD_SET(i32 %45, i32* %3)
%47 = load i32, i32* %35
%48 = call i32 @FD_SET(i32 %47, i32* %3)
%49 = load i32, i32* %35
%50 = add nsw i32 %49, 1
%51 = call i32 @select(i32 %50, i32* %3, i32* null, i32* null, %struct.timeval* %6)
br label %65
52: ; preds = %27
%53 = call i32 @FD_ZERO(i32* %4)
%54 = load i32, i32* %29
%55 = call i32 @FD_SET(i32 %54, i32* %4)
%56 = load i32, i32* %31
%57 = call i32 @FD_SET(i32 %56, i32* %4)
%58 = load i32, i32* %33
%59 = call i32 @FD_SET(i32 %58, i32* %4)
%60 = load i32, i32* %35
%61 = call i32 @FD_SET(i32 %60, i32* %4)
%62 = load i32, i32* %35
%63 = add nsw i32 %62, 1
%64 = call i32 @select(i32 %63, i32* null, i32* %4, i32* null, %struct.timeval* %6)
br label %65
65: ; preds = %52, %39
%66 = phi i32 [ %51, %39 ], [ %64, %52 ]
switch i32 %66, label %69 [
i32 -1, label %67
i32 0, label %135
]
67: ; preds = %65
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, i64 0, i64 0))
br label %142
69: ; preds = %65
%70 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %28)
%71 = icmp eq i64 %70, 0
%72 = load i32, i32* %29
br i1 %71, label %76, label %73
73: ; preds = %69
%74 = call i64 @FD_ISSET(i32 %72, i32* %4)
%75 = icmp eq i64 %74, 0
br i1 %75, label %117, label %115
76: ; preds = %69
%77 = call i64 @FD_ISSET(i32 %72, i32* %3)
%78 = icmp eq i64 %77, 0
br i1 %78, label %85, label %79
79: ; preds = %76
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%81 = call i32 @memset(i8* %11, i32 0, i32 100)
%82 = load i32, i32* %29
%83 = call i32 @read(i32 %82, i8* %11, i32 100)
%84 = call i32 @puts(i8* %11)
br label %85
85: ; preds = %76, %79
%86 = load i32, i32* %31
%87 = call i64 @FD_ISSET(i32 %86, i32* %3)
%88 = icmp eq i64 %87, 0
br i1 %88, label %95, label %89
89: ; preds = %85
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%91 = call i32 @memset(i8* %11, i32 0, i32 100)
%92 = load i32, i32* %31
%93 = call i32 @read(i32 %92, i8* %11, i32 100)
%94 = call i32 @puts(i8* %11)
br label %95
95: ; preds = %89, %85
%96 = load i32, i32* %33
%97 = call i64 @FD_ISSET(i32 %96, i32* %3)
%98 = icmp eq i64 %97, 0
br i1 %98, label %105, label %99
99: ; preds = %95
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%101 = call i32 @memset(i8* %11, i32 0, i32 100)
%102 = load i32, i32* %33
%103 = call i32 @read(i32 %102, i8* %11, i32 100)
%104 = call i32 @puts(i8* %11)
br label %105
105: ; preds = %99, %95
%106 = load i32, i32* %35
%107 = call i64 @FD_ISSET(i32 %106, i32* %3)
%108 = icmp eq i64 %107, 0
br i1 %108, label %142, label %109
109: ; preds = %105
%110 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%111 = call i32 @memset(i8* %11, i32 0, i32 100)
%112 = load i32, i32* %35
%113 = call i32 @read(i32 %112, i8* %11, i32 100)
%114 = call i32 @puts(i8* %11)
br label %142
115: ; preds = %73
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %117
117: ; preds = %73, %115
%118 = load i32, i32* %31
%119 = call i64 @FD_ISSET(i32 %118, i32* %4)
%120 = icmp eq i64 %119, 0
br i1 %120, label %123, label %121
121: ; preds = %117
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %123
123: ; preds = %121, %117
%124 = load i32, i32* %33
%125 = call i64 @FD_ISSET(i32 %124, i32* %4)
%126 = icmp eq i64 %125, 0
br i1 %126, label %129, label %127
127: ; preds = %123
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %129
129: ; preds = %127, %123
%130 = load i32, i32* %35
%131 = call i64 @FD_ISSET(i32 %130, i32* %4)
%132 = icmp eq i64 %131, 0
br i1 %132, label %142, label %133
133: ; preds = %129
%134 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %142
135: ; preds = %65
%136 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %28)
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %135
%139 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
br label %142
140: ; preds = %135
%141 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %142
142: ; preds = %129, %133, %105, %109, %67, %140, %138, %25
%143 = phi i32 [ -1, %25 ], [ -1, %67 ], [ 0, %140 ], [ 0, %138 ], [ 0, %109 ], [ 0, %105 ], [ 0, %133 ], [ 0, %129 ]
ret i32 %143
}