#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 */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dump_fdset(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
void main(void) {
  int fd1, fd2, fd3, fd4, fd5, fd6;
  fd_set fds_read, fds_write;
  struct timeval timeout;
  int retval;
  fd1 = open("dummy1.txt", O_CREAT | O_RDONLY);
  if (fd1 < 0) {
    perror("Error opening file");
    exit(-1);
  }
  fd2 = open("dummy2.txt", O_CREAT | O_RDONLY);
  if (fd2 < 0) {
    perror("Error opening file");
    exit(-1);
  }
  fd3 = open("dummy3.txt", O_CREAT | O_WRONLY);
  if (fd3 < 0) {
    perror("Error opening file");
    exit(-1);
  }
  fd4 = open("dummy4.txt", O_CREAT | O_WRONLY);
  if (fd4 < 0) {
    perror("Error opening file");
    exit(-1);
  }
  fd5 = open("dummy5.txt", O_CREAT | O_RDWR);
  if (fd5 < 0) {
    perror("Error opening file");
    exit(-1);
  }
  fd6 = open("dummy6.txt", O_CREAT | O_RDWR);
  if (fd6 < 0) {
    perror("Error opening file");
    exit(-1);
  }
  FD_ZERO(&fds_read);
  FD_ZERO(&fds_write);
  FD_SET(fd1, &fds_write);
  FD_SET(fd2, &fds_write);
  FD_SET(fd3, &fds_read);
  FD_SET(fd4, &fds_read);
  FD_SET(fd5, &fds_read);
  FD_SET(fd5, &fds_write);
  FD_SET(fd6, &fds_read);
  FD_SET(fd6, &fds_write);
  printf("* Dump INPUT fds_read:\n");
  dump_fdset(&fds_read);
  printf("* Dump INPUT fds_write:\n");
  dump_fdset(&fds_write);
  retval = select(9, &fds_read, &fds_write, NULL, NULL);
  printf("\n***********************\n");
  printf("After select: \n");
  printf("Return value: %d\n", retval);
  printf("* Dump RESULTING fds_read:\n");
  dump_fdset(&fds_read);
  printf("* Dump RESULTING fds_write:\n");
  dump_fdset(&fds_write);
  FD_ZERO(&fds_read);
  FD_ZERO(&fds_write);
  FD_SET(fd1, &fds_write);
  FD_SET(fd2, &fds_write);
  FD_SET(fd3, &fds_read);
  FD_SET(fd4, &fds_read);
  timeout.tv_sec = 5;
  timeout.tv_usec = 0;
  retval = select(7, &fds_read, &fds_write, NULL, NULL);
  printf("\n***********************\n");
  printf("After select: \n");
  printf("Return value: %d\n", retval);
  printf("* Dump RESULTING fds_read:\n");
  dump_fdset(&fds_read);
  printf("* Dump RESULTING fds_write:\n");
  dump_fdset(&fds_write);
  close(fd1);
  close(fd2);
  close(fd3);
  close(fd4);
  close(fd5);
  close(fd6);
  unlink("dummy1.txt");
  unlink("dummy2.txt");
  unlink("dummy3.txt");
  unlink("dummy4.txt");
  unlink("dummy5.txt");
  unlink("dummy6.txt");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11e9 <main+0x49>
lea    0xe31(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    122a <main+0x8a>
lea    0xdf0(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
or     (%rax),%esi
lea    0xde6(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    126b <main+0xcb>
lea    0xdaf(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
lea    0xdb0(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12ac <main+0x10c>
lea    0xd6e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
mov    0x2d24(%rip),%rax
or     (%rax),%esi
lea    0xd7a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ed <main+0x14d>
lea    0xd2d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
mov    0x2ce3(%rip),%rax
or     (%rax),%esi
lea    0xd44(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    132e <main+0x18e>
lea    0xcec(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <FD_ZERO@plt>
lea    -0x20(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <FD_SET@plt>
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <dump_fdset@plt>
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1090 <dump_fdset@plt>
mov    $0x9,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1070 <select@plt>
mov    %eax,-0x34(%rbp)
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xca3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <dump_fdset@plt>
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1090 <dump_fdset@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <FD_ZERO@plt>
lea    -0x20(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
movl   $0x5,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x7,%edi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1070 <select@plt>
mov    %eax,-0x34(%rbp)
lea    0xbcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xbd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   1090 <dump_fdset@plt>
lea    0xbdf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1090 <dump_fdset@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
lea    0xaba(%rip),%rdi
call   1030 <unlink@plt>
lea    0xacc(%rip),%rdi
call   1030 <unlink@plt>
lea    0xacb(%rip),%rdi
call   1030 <unlink@plt>
lea    0xaca(%rip),%rdi
call   1030 <unlink@plt>
lea    0xac9(%rip),%rdi
call   1030 <unlink@plt>
lea    0xac8(%rip),%rdi
call   1030 <unlink@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e33(%rip),%r14
mov    0x2e0c(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
lea    0xe27(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     14d7 <main+0x327>
mov    %eax,%r13d
mov    0x0(%rbp),%esi
or     (%r14),%esi
lea    0xe28(%rip),%rdi
call   1090 <open@plt>
mov    %eax,0x1c(%rsp)
test   %eax,%eax
js     14d7 <main+0x327>
mov    0x2db2(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
lea    0xe0e(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     14d7 <main+0x327>
mov    %eax,%ebx
mov    0x0(%rbp),%esi
or     (%r14),%esi
lea    0xdfd(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     14d7 <main+0x327>
mov    %eax,%r12d
mov    0x2d92(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
lea    0xde4(%rip),%rdi
call   1090 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     14d7 <main+0x327>
mov    (%r15),%esi
or     (%r14),%esi
lea    0xdd1(%rip),%rdi
call   1090 <open@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
js     14d7 <main+0x327>
lea    0x24(%rsp),%r15
mov    %r15,%rdi
call   1070 <FD_ZERO@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1070 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0x1c(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    %ebx,0x18(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    %r12d,0x14(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
lea    0xd55(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   10a0 <dump_fdset@plt>
lea    0xd58(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10a0 <dump_fdset@plt>
mov    $0x9,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
mov    %r13d,0x10(%rsp)
mov    %eax,%r12d
lea    0xd3f(%rip),%rdi
call   1040 <puts@plt>
lea    0xd4c(%rip),%rdi
call   1040 <puts@plt>
lea    0xce6(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd3e(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   10a0 <dump_fdset@plt>
lea    0xd45(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10a0 <dump_fdset@plt>
mov    %r15,%rdi
call   1070 <FD_ZERO@plt>
mov    %r14,%rdi
call   1070 <FD_ZERO@plt>
mov    %r13d,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    %ebp,%edi
mov    %ebp,%r13d
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0x18(%rsp),%r12d
mov    %r12d,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    0x14(%rsp),%ebp
mov    %ebp,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    $0x7,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
mov    %eax,%ebx
lea    0xc91(%rip),%rdi
call   1040 <puts@plt>
lea    0xc9e(%rip),%rdi
call   1040 <puts@plt>
lea    0xc38(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc91(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   10a0 <dump_fdset@plt>
lea    0xc98(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10a0 <dump_fdset@plt>
mov    0x10(%rsp),%edi
call   1060 <close@plt>
mov    %r13d,%edi
call   1060 <close@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xb79(%rip),%rdi
call   1030 <unlink@plt>
lea    0xb8b(%rip),%rdi
call   1030 <unlink@plt>
lea    0xb8a(%rip),%rdi
call   1030 <unlink@plt>
lea    0xb89(%rip),%rdi
call   1030 <unlink@plt>
lea    0xb88(%rip),%rdi
call   1030 <unlink@plt>
lea    0xb87(%rip),%rdi
call   1030 <unlink@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb2d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [11 x i8] c"dummy1.txt\00"
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Error opening file\00"
@.str.2 = [11 x i8] c"dummy2.txt\00"
@.str.3 = [11 x i8] c"dummy3.txt\00"
@O_WRONLY = global i32 0
@.str.4 = [11 x i8] c"dummy4.txt\00"
@.str.5 = [11 x i8] c"dummy5.txt\00"
@O_RDWR = global i32 0
@.str.6 = [11 x i8] c"dummy6.txt\00"
@.str.7 = [24 x i8] c"* Dump INPUT fds_read:\0A\00"
@.str.8 = [25 x i8] c"* Dump INPUT fds_write:\0A\00"
@.str.9 = [26 x i8] c"\0A***********************\0A\00"
@.str.10 = [16 x i8] c"After select: \0A\00"
@.str.11 = [18 x i8] c"Return value: %d\0A\00"
@.str.12 = [28 x i8] c"* Dump RESULTING fds_read:\0A\00"
@.str.13 = [29 x i8] c"* Dump RESULTING fds_write:\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca i32
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDONLY
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %1
%15 = load i32, i32* %1
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @O_RDONLY
%23 = or i32 %21, %22
%24 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %20
%31 = load i32, i32* @O_CREAT
%32 = load i32, i32* @O_WRONLY
%33 = or i32 %31, %32
%34 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %30
%41 = load i32, i32* @O_CREAT
%42 = load i32, i32* @O_WRONLY
%43 = or i32 %41, %42
%44 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %43)
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %40
%51 = load i32, i32* @O_CREAT
%52 = load i32, i32* @O_RDWR
%53 = or i32 %51, %52
%54 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %53)
store i32 %54, i32* %5
%55 = load i32, i32* %5
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 -1)
unreachable
60: ; preds = %50
%61 = load i32, i32* @O_CREAT
%62 = load i32, i32* @O_RDWR
%63 = or i32 %61, %62
%64 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %63)
store i32 %64, i32* %6
%65 = load i32, i32* %6
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %60
%71 = call i32 @FD_ZERO(i32* %7)
%72 = call i32 @FD_ZERO(i32* %8)
%73 = load i32, i32* %1
%74 = call i32 @FD_SET(i32 %73, i32* %8)
%75 = load i32, i32* %2
%76 = call i32 @FD_SET(i32 %75, i32* %8)
%77 = load i32, i32* %3
%78 = call i32 @FD_SET(i32 %77, i32* %7)
%79 = load i32, i32* %4
%80 = call i32 @FD_SET(i32 %79, i32* %7)
%81 = load i32, i32* %5
%82 = call i32 @FD_SET(i32 %81, i32* %7)
%83 = load i32, i32* %5
%84 = call i32 @FD_SET(i32 %83, i32* %8)
%85 = load i32, i32* %6
%86 = call i32 @FD_SET(i32 %85, i32* %7)
%87 = load i32, i32* %6
%88 = call i32 @FD_SET(i32 %87, i32* %8)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%90 = call i32 @dump_fdset(i32* %7)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%92 = call i32 @dump_fdset(i32* %8)
%93 = call i32 @select(i32 9, i32* %7, i32* %8, i32* null, i32* null)
store i32 %93, i32* %10
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%96 = load i32, i32* %10
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0))
%99 = call i32 @dump_fdset(i32* %7)
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%101 = call i32 @dump_fdset(i32* %8)
%102 = call i32 @FD_ZERO(i32* %7)
%103 = call i32 @FD_ZERO(i32* %8)
%104 = load i32, i32* %1
%105 = call i32 @FD_SET(i32 %104, i32* %8)
%106 = load i32, i32* %2
%107 = call i32 @FD_SET(i32 %106, i32* %8)
%108 = load i32, i32* %3
%109 = call i32 @FD_SET(i32 %108, i32* %7)
%110 = load i32, i32* %4
%111 = call i32 @FD_SET(i32 %110, i32* %7)
%112 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i32 5, i32* %112
%113 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i64 0, i64* %113
%114 = call i32 @select(i32 7, i32* %7, i32* %8, i32* null, i32* null)
store i32 %114, i32* %10
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%117 = load i32, i32* %10
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0))
%120 = call i32 @dump_fdset(i32* %7)
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
%122 = call i32 @dump_fdset(i32* %8)
%123 = load i32, i32* %1
%124 = call i32 @close(i32 %123)
%125 = load i32, i32* %2
%126 = call i32 @close(i32 %125)
%127 = load i32, i32* %3
%128 = call i32 @close(i32 %127)
%129 = load i32, i32* %4
%130 = call i32 @close(i32 %129)
%131 = load i32, i32* %5
%132 = call i32 @close(i32 %131)
%133 = load i32, i32* %6
%134 = call i32 @close(i32 %133)
%135 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%136 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%137 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%138 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%139 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%140 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"dummy1.txt\00"
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"Error opening file\00"
@.str.2 = [11 x i8] c"dummy2.txt\00"
@.str.3 = [11 x i8] c"dummy3.txt\00"
@O_WRONLY = global i32 0
@.str.4 = [11 x i8] c"dummy4.txt\00"
@.str.5 = [11 x i8] c"dummy5.txt\00"
@O_RDWR = global i32 0
@.str.6 = [11 x i8] c"dummy6.txt\00"
@.str.11 = [18 x i8] c"Return value: %d\0A\00"
@str = [23 x i8] c"* Dump INPUT fds_read:\00"
@str.14 = [24 x i8] c"* Dump INPUT fds_write:\00"
@str.19 = [25 x i8] c"\0A***********************\00"
@str.20 = [15 x i8] c"After select: \00"
@str.21 = [27 x i8] c"* Dump RESULTING fds_read:\00"
@str.22 = [28 x i8] c"* Dump RESULTING fds_write:\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_RDONLY
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = load i32, i32* @O_CREAT
%15 = load i32, i32* @O_RDONLY
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %13
%23 = load i32, i32* @O_CREAT
%24 = load i32, i32* @O_WRONLY
%25 = or i32 %24, %23
%26 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %22
%32 = load i32, i32* @O_CREAT
%33 = load i32, i32* @O_WRONLY
%34 = or i32 %33, %32
%35 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 @exit(i32 -1)
unreachable
40: ; preds = %31
%41 = load i32, i32* @O_CREAT
%42 = load i32, i32* @O_RDWR
%43 = or i32 %42, %41
%44 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%48 = tail call i32 @exit(i32 -1)
unreachable
49: ; preds = %40
%50 = load i32, i32* @O_CREAT
%51 = load i32, i32* @O_RDWR
%52 = or i32 %51, %50
%53 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%57 = tail call i32 @exit(i32 -1)
unreachable
58: ; preds = %49
%59 = call i32 @FD_ZERO(i32* %1)
%60 = call i32 @FD_ZERO(i32* %2)
%61 = call i32 @FD_SET(i32 %8, i32* %2)
%62 = call i32 @FD_SET(i32 %17, i32* %2)
%63 = call i32 @FD_SET(i32 %26, i32* %1)
%64 = call i32 @FD_SET(i32 %35, i32* %1)
%65 = call i32 @FD_SET(i32 %44, i32* %1)
%66 = call i32 @FD_SET(i32 %44, i32* %2)
%67 = call i32 @FD_SET(i32 %53, i32* %1)
%68 = call i32 @FD_SET(i32 %53, i32* %2)
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%70 = call i32 @dump_fdset(i32* %1)
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%72 = call i32 @dump_fdset(i32* %2)
%73 = call i32 @select(i32 9, i32* %1, i32* %2, i32* null, i32* null)
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.19, i64 0, i64 0))
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.20, i64 0, i64 0))
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %73)
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.21, i64 0, i64 0))
%78 = call i32 @dump_fdset(i32* %1)
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.22, i64 0, i64 0))
%80 = call i32 @dump_fdset(i32* %2)
%81 = call i32 @FD_ZERO(i32* %1)
%82 = call i32 @FD_ZERO(i32* %2)
%83 = call i32 @FD_SET(i32 %8, i32* %2)
%84 = call i32 @FD_SET(i32 %17, i32* %2)
%85 = call i32 @FD_SET(i32 %26, i32* %1)
%86 = call i32 @FD_SET(i32 %35, i32* %1)
%87 = call i32 @select(i32 7, i32* %1, i32* %2, i32* null, i32* null)
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.19, i64 0, i64 0))
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.20, i64 0, i64 0))
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %87)
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.21, i64 0, i64 0))
%92 = call i32 @dump_fdset(i32* %1)
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.22, i64 0, i64 0))
%94 = call i32 @dump_fdset(i32* %2)
%95 = call i32 @close(i32 %8)
%96 = call i32 @close(i32 %17)
%97 = call i32 @close(i32 %26)
%98 = call i32 @close(i32 %35)
%99 = call i32 @close(i32 %44)
%100 = call i32 @close(i32 %53)
%101 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%102 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%103 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%104 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%105 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%106 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret void
}