#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 O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mkfifo(char *, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  char buffer[256];
  int fd1, fd2, read1, read2;
  fd_set set;
  struct timeval t;
  t.tv_sec = 2;
  t.tv_usec = 0;
  mkfifo("tub1", 0644);
  mkfifo("tub2", 0644);
  printf("Abrimos la primera tubería.\n");
  fd1 = open("tub1", O_RDONLY | O_NONBLOCK);
  printf("Abrimos la segunda tubería.\n");
  fd2 = open("tub2", O_RDONLY | O_NONBLOCK);
  if (fd1 < 0 || fd2 < 0)
    perror("Error al abrir las tuberías.\n");
  printf("Valor fd1: %d\n", fd1);
  printf("Valor fd2: %d\n", fd2);
  while (1) {
    sleep(3);
    FD_ZERO(&set);
    FD_SET(fd1, &set);
    FD_SET(fd2, &set);
    select((((fd1) > (fd2)) ? (fd1) : (fd2)) + 1, &set, NULL, NULL, &t);
    if (FD_ISSET(fd1, &set)) {
      read1 = read(fd1, buffer, 256);
      if (read1 < 0)
        perror("Error de read1.\n");
      printf("tub1:");
      buffer[read1] = '\0';
      printf("%s", buffer);
      close(fd1);
      fd1 = open("./tub1", O_RDONLY | O_NONBLOCK);
    }
    if (FD_ISSET(fd2, &set)) {
      read2 = read(fd2, buffer, 256);
      if (read2 < 0)
        perror("Error de read2.\n");
      printf("tub2:");
      buffer[read2] = '\0';
      printf("%s", buffer);
      close(fd2);
      fd2 = open("./tub2", O_RDONLY | O_NONBLOCK);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x138(%rbp)
movq   $0x0,-0x130(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x1a4,%esi
call   1070 <mkfifo@plt>
lea    0xebd(%rip),%rdi
mov    $0x1a4,%esi
call   1070 <mkfifo@plt>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    0x2dca(%rip),%rax
or     (%rax),%esi
lea    0xe6e(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x114(%rbp)
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
or     (%rax),%esi
lea    0xe5a(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x114(%rbp)
jl     127e <main+0xce>
cmpl   $0x0,-0x118(%rbp)
jge    128a <main+0xda>
lea    0xdb7(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x114(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3,%edi
call   10d0 <sleep@plt>
lea    -0x124(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x114(%rbp),%edi
lea    -0x124(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x118(%rbp),%edi
lea    -0x124(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x114(%rbp),%eax
cmp    -0x118(%rbp),%eax
jle    130f <main+0x15f>
mov    -0x114(%rbp),%eax
mov    %eax,-0x13c(%rbp)
jmp    131b <main+0x16b>
mov    -0x118(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x13c(%rbp),%edi
add    $0x1,%edi
lea    -0x124(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x138(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    -0x114(%rbp),%edi
lea    -0x124(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13f1 <main+0x241>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jge    1390 <main+0x1e0>
lea    0xcee(%rip),%rdi
call   10b0 <perror@plt>
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x11c(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rsi
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x114(%rbp),%edi
call   1050 <close@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%esi
mov    0x2c0b(%rip),%rax
or     (%rax),%esi
lea    0xcad(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x114(%rbp)
mov    -0x118(%rbp),%edi
lea    -0x124(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14a4 <main+0x2f4>
mov    -0x118(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0x0,-0x120(%rbp)
jge    1443 <main+0x293>
lea    0xc5c(%rip),%rdi
call   10b0 <perror@plt>
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x120(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rsi
lea    0xc22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%edi
call   1050 <close@plt>
mov    0x2b59(%rip),%rax
mov    (%rax),%esi
mov    0x2b58(%rip),%rax
or     (%rax),%esi
lea    0xc18(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x118(%rbp)
jmp    12b2 <main+0x102>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
movl   $0x2,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe70(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1080 <mkfifo@plt>
lea    0xe7a(%rip),%r14
mov    %r14,%rdi
mov    $0x1a4,%esi
call   1080 <mkfifo@plt>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dc3(%rip),%r15
mov    0x2dc4(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%r12d
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
or     %r12d,%eax
js     13f0 <main+0x230>
lea    0xdbe(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdbc(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1c(%rsp),%r14
lea    0x8(%rsp),%rbx
lea    0x20(%rsp),%r13
jmp    12f6 <main+0x136>
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     13d1 <main+0x211>
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebx,%rax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xd8e(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
lea    0xd8b(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    $0x3,%edi
call   10e0 <sleep@plt>
mov    %r14,%rdi
call   1090 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
cmp    %ebp,%r12d
mov    %ebp,%edi
cmovg  %r12d,%edi
add    $0x1,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   10a0 <select@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
jne    135c <main+0x19c>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     12f6 <main+0x136>
jmp    1290 <main+0xd0>
mov    %r12d,%edi
mov    %r13,%rbx
mov    %r13,%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%r15d
test   %eax,%eax
js     13e2 <main+0x222>
lea    0xcd1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %r15d,%rax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xcc1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
mov    0x2c2b(%rip),%r15
or     (%r15),%esi
lea    0xc98(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%r12d
lea    0x8(%rsp),%rbx
jmp    1348 <main+0x188>
lea    0xc86(%rip),%rdi
call   10c0 <perror@plt>
jmp    12a9 <main+0xe9>
lea    0xc54(%rip),%rdi
call   10c0 <perror@plt>
jmp    1376 <main+0x1b6>
lea    0xc09(%rip),%rdi
call   10c0 <perror@plt>
jmp    125a <main+0x9a>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [5 x i8] c"tub1\00"
@.str.1 = [5 x i8] c"tub2\00"
@.str.2 = [30 x i8] c"Abrimos la primera tuber\C3\ADa.\0A\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [30 x i8] c"Abrimos la segunda tuber\C3\ADa.\0A\00"
@.str.4 = [31 x i8] c"Error al abrir las tuber\C3\ADas.\0A\00"
@.str.5 = [15 x i8] c"Valor fd1: %d\0A\00"
@.str.6 = [15 x i8] c"Valor fd2: %d\0A\00"
@.str.7 = [17 x i8] c"Error de read1.\0A\00"
@.str.8 = [6 x i8] c"tub1:\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [7 x i8] c"./tub1\00"
@.str.11 = [17 x i8] c"Error de read2.\0A\00"
@.str.12 = [6 x i8] c"tub2:\00"
@.str.13 = [7 x i8] c"./tub2\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 2, i32* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i64 0, i64* %14
%15 = call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 420)
%16 = call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 420)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @O_RDONLY
%19 = load i32, i32* @O_NONBLOCK
%20 = or i32 %18, %19
%21 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @O_RDONLY
%24 = load i32, i32* @O_NONBLOCK
%25 = or i32 %23, %24
%26 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %2
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29, %2
%33 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %34, %106
%40 = call i32 @sleep(i32 3)
%41 = call i32 @FD_ZERO(i32* %11)
%42 = load i32, i32* %7
%43 = call i32 @FD_SET(i32 %42, i32* %11)
%44 = load i32, i32* %8
%45 = call i32 @FD_SET(i32 %44, i32* %11)
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = icmp sgt i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %39
%50 = load i32, i32* %7
br label %53
51: ; preds = %39
%52 = load i32, i32* %8
br label %53
53: ; preds = %51, %49
%54 = phi i32 [ %50, %49 ], [ %52, %51 ]
%55 = add nsw i32 %54, 1
%56 = call i32 @select(i32 %55, i32* %11, i32* null, i32* null, %struct.timeval* %12)
%57 = load i32, i32* %7
%58 = call i64 @FD_ISSET(i32 %57, i32* %11)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %81
60: ; preds = %53
%61 = load i32, i32* %7
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%63 = call i32 @read(i32 %61, i8* %62, i32 256)
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %68
68: ; preds = %66, %60
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %71
store i8 0, i8* %72
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %73)
%75 = load i32, i32* %7
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* @O_RDONLY
%78 = load i32, i32* @O_NONBLOCK
%79 = or i32 %77, %78
%80 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %79)
store i32 %80, i32* %7
br label %81
81: ; preds = %68, %53
%82 = load i32, i32* %8
%83 = call i64 @FD_ISSET(i32 %82, i32* %11)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %106
85: ; preds = %81
%86 = load i32, i32* %8
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%88 = call i32 @read(i32 %86, i8* %87, i32 256)
store i32 %88, i32* %10
%89 = load i32, i32* %10
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %85
%92 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %93
93: ; preds = %91, %85
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %96
store i8 0, i8* %97
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %98)
%100 = load i32, i32* %8
%101 = call i32 @close(i32 %100)
%102 = load i32, i32* @O_RDONLY
%103 = load i32, i32* @O_NONBLOCK
%104 = or i32 %102, %103
%105 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %104)
store i32 %105, i32* %8
br label %106
106: ; preds = %93, %81
br label %39
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [5 x i8] c"tub1\00"
@.str.1 = [5 x i8] c"tub2\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [31 x i8] c"Error al abrir las tuber\C3\ADas.\0A\00"
@.str.5 = [15 x i8] c"Valor fd1: %d\0A\00"
@.str.6 = [15 x i8] c"Valor fd2: %d\0A\00"
@.str.7 = [17 x i8] c"Error de read1.\0A\00"
@.str.8 = [6 x i8] c"tub1:\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [7 x i8] c"./tub1\00"
@.str.11 = [17 x i8] c"Error de read2.\0A\00"
@.str.12 = [6 x i8] c"tub2:\00"
@.str.13 = [7 x i8] c"./tub2\00"
@str = [29 x i8] c"Abrimos la primera tuber\C3\ADa.\00"
@str.14 = [29 x i8] c"Abrimos la segunda tuber\C3\ADa.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 2, i32* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 0, i64* %10
%11 = tail call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 420)
%12 = tail call i32 @mkfifo(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 420)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %15, %14
%17 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.14, i64 0, i64 0))
%19 = load i32, i32* @O_RDONLY
%20 = load i32, i32* @O_NONBLOCK
%21 = or i32 %20, %19
%22 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = or i32 %22, %17
%24 = icmp sgt i32 %23, -1
br i1 %24, label %27, label %25
25: ; preds = %2
%26 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %2, %25
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %22)
br label %30
30: ; preds = %69, %27
%31 = phi i32 [ %78, %69 ], [ %22, %27 ]
%32 = phi i32 [ %61, %69 ], [ %17, %27 ]
br label %33
33: ; preds = %30, %60
%34 = phi i32 [ %61, %60 ], [ %32, %30 ]
%35 = call i32 @sleep(i32 3)
%36 = call i32 @FD_ZERO(i32* %4)
%37 = call i32 @FD_SET(i32 %34, i32* %4)
%38 = call i32 @FD_SET(i32 %31, i32* %4)
%39 = icmp sgt i32 %34, %31
%40 = select i1 %39, i32 %34, i32 %31
%41 = add nsw i32 %40, 1
%42 = call i32 @select(i32 %41, i32* %4, i32* null, i32* null, %struct.timeval* %5)
%43 = call i64 @FD_ISSET(i32 %34, i32* %4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %60, label %45
45: ; preds = %33
%46 = call i32 @read(i32 %34, i8* %6, i32 256)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%52 = sext i32 %46 to i64
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %52
store i8 0, i8* %53
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %6)
%55 = call i32 @close(i32 %34)
%56 = load i32, i32* @O_RDONLY
%57 = load i32, i32* @O_NONBLOCK
%58 = or i32 %57, %56
%59 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %50, %33
%61 = phi i32 [ %59, %50 ], [ %34, %33 ]
%62 = call i64 @FD_ISSET(i32 %31, i32* %4)
%63 = icmp eq i64 %62, 0
br i1 %63, label %33, label %64
64: ; preds = %60
%65 = call i32 @read(i32 %31, i8* %6, i32 256)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%71 = sext i32 %65 to i64
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %71
store i8 0, i8* %72
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %6)
%74 = call i32 @close(i32 %31)
%75 = load i32, i32* @O_RDONLY
%76 = load i32, i32* @O_NONBLOCK
%77 = or i32 %76, %75
%78 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), i32 %77)
br label %30
}