#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 timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int EXIT_SUCCESS;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int pselect(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
            int /*<<< orphan*/ *, struct timespec *, int /*<<< orphan*/ *);
int read(int, char *, int);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int main() {
  int fd1, fd2;
  fd_set read_set, write_set, except_set;
  char buf[10];
  struct timespec timeout;
  sigset_t mask;
  int n;
  timeout.tv_sec = 90;
  timeout.tv_nsec = 0;
  sigaddset(&mask, SIGINT);
  sigaddset(&mask, SIGQUIT);
  fd1 = open("./pone", O_RDWR);
  fd2 = open("./ptwo", O_RDWR);
  while (1) {
    FD_ZERO(&read_set);
    FD_SET(fd1, &read_set);
    FD_SET(fd2, &read_set);
    n = pselect(FD_SETSIZE, &read_set, NULL, NULL, &timeout, &mask);
    if (n < 0) {
      perror("select ");
      exit(1);
    }
    if (FD_ISSET(fd1, &read_set)) {
      printf(" reading from fd1 (pone)\n");
      n = read(fd1, buf, 10);
      printf(" read %d from pone \n", n);
    }
    if (FD_ISSET(fd2, &read_set)) {
      printf(" reading from fd2 (ptwo)\n");
      n = read(fd2, buf, 10);
      printf(" read %d from ptwo \n", n);
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5a,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe0e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    0xdfd(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1070 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x38(%rbp),%r8
lea    -0x3c(%rbp),%r9
mov    %rcx,%rdx
call   1040 <pselect@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1277 <main+0xd7>
lea    0xda6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12c0 <main+0x120>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1309 <main+0x169>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1212 <main+0x72>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x5a,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10d0 <sigaddset@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10d0 <sigaddset@plt>
mov    0x2ded(%rip),%rbx
mov    (%rbx),%esi
lea    0xdfc(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    (%rbx),%esi
lea    0xdf2(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%rbp
mov    0x2da0(%rip),%r14
lea    0x8(%rsp),%r12
lea    0x1e(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1080 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    (%r14),%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %rsp,%r9
call   1050 <pselect@plt>
test   %eax,%eax
js     12f5 <main+0x145>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     12b2 <main+0x102>
lea    0xdcc(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0xa,%edx
call   1070 <read@plt>
lea    0xd6d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1240 <main+0x90>
lea    0xd74(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0xa,%edx
call   1070 <read@plt>
lea    0xd44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1240 <main+0x90>
lea    0xd12(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@.str = [7 x i8] c"./pone\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"./ptwo\00"
@FD_SETSIZE = global i32 0
@.str.2 = [8 x i8] c"select \00"
@.str.3 = [26 x i8] c" reading from fd1 (pone)\0A\00"
@.str.4 = [21 x i8] c" read %d from pone \0A\00"
@.str.5 = [26 x i8] c" reading from fd2 (ptwo)\0A\00"
@.str.6 = [21 x i8] c" read %d from ptwo \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [10 x i8]
%8 = alloca %struct.timespec
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
store i32 90, i32* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
store i64 0, i64* %12
%13 = load i32, i32* @SIGINT
%14 = call i32 @sigaddset(i32* %9, i32 %13)
%15 = load i32, i32* @SIGQUIT
%16 = call i32 @sigaddset(i32* %9, i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %0, %56
%22 = call i32 @FD_ZERO(i32* %4)
%23 = load i32, i32* %2
%24 = call i32 @FD_SET(i32 %23, i32* %4)
%25 = load i32, i32* %3
%26 = call i32 @FD_SET(i32 %25, i32* %4)
%27 = load i32, i32* @FD_SETSIZE
%28 = call i32 @pselect(i32 %27, i32* %4, i32* null, i32* null, %struct.timespec* %8, i32* %9)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %21
%32 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %21
%35 = load i32, i32* %2
%36 = call i64 @FD_ISSET(i32 %35, i32* %4)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* %2
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 10)
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38, %34
%46 = load i32, i32* %3
%47 = call i64 @FD_ISSET(i32 %46, i32* %4)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* %3
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%53 = call i32 @read(i32 %51, i8* %52, i32 10)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %49, %45
br label %21
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@.str = [7 x i8] c"./pone\00"
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"./ptwo\00"
@FD_SETSIZE = global i32 0
@.str.2 = [8 x i8] c"select \00"
@.str.4 = [21 x i8] c" read %d from pone \0A\00"
@.str.6 = [21 x i8] c" read %d from ptwo \0A\00"
@EXIT_SUCCESS = global i32 0
@str = [25 x i8] c" reading from fd2 (ptwo)\00"
@str.7 = [25 x i8] c" reading from fd1 (pone)\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.timespec* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 90, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 0, i64* %10
%11 = load i32, i32* @SIGINT
%12 = call i32 @sigaddset(i32* %4, i32 %11)
%13 = load i32, i32* @SIGQUIT
%14 = call i32 @sigaddset(i32* %4, i32 %13)
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %43, %0
%20 = call i32 @FD_ZERO(i32* %1)
%21 = call i32 @FD_SET(i32 %16, i32* %1)
%22 = call i32 @FD_SET(i32 %18, i32* %1)
%23 = load i32, i32* @FD_SETSIZE
%24 = call i32 @pselect(i32 %23, i32* %1, i32* null, i32* null, %struct.timespec* %3, i32* %4)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = call i64 @FD_ISSET(i32 %16, i32* %1)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%34 = call i32 @read(i32 %16, i8* %6, i32 10)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %29
%37 = call i64 @FD_ISSET(i32 %18, i32* %1)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%41 = call i32 @read(i32 %18, i8* %6, i32 10)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %39, %36
br label %19
}