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

/* 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*/ O_RDONLY;
scalar_t__ atoi(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int result;
  fd_set readset;
  bool is_in_1_open, is_in_2_open;
  int sum = 0;
  int in_1, in_2;
  bool in_1_closed, in_2_closed;
  char buff[255];
  if (-1 == (in_1 = open("in1", O_RDONLY))) {
    return 1;
  }
  in_1_closed = false;
  if (-1 == (in_2 = open("in2", O_RDONLY))) {
    return 1;
  }
  in_2_closed = false;
  while (!in_1_closed && FD_ISSET(in_1, &readset) ||
         !in_2_closed && FD_ISSET(in_2, &readset)) {
    FD_ZERO(&readset);
    FD_SET(in_1, &readset);
    FD_SET(in_2, &readset);
    result = select(in_2 + 1, &readset, NULL, NULL, NULL);
    if (result > 0) {
      if (!in_1_closed && FD_ISSET(in_1, &readset)) {
        result = read(in_1, buff, sizeof(buff));
        if (0 == result)
          in_1_closed = true;
        else
          sum += atoi(buff);
      }
      if (!in_2_closed && FD_ISSET(in_2, &readset)) {
        result = read(in_2, buff, sizeof(buff));
        if (0 == result)
          in_2_closed = true;
        else
          sum += atoi(buff);
      }
    } else if (result < 0) {
      printf("Error on select()\n");
    }
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11d3 <main+0x53>
movl   $0x1,-0x4(%rbp)
jmp    13e8 <main+0x268>
movl   $0x0,-0x30(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    120d <main+0x8d>
movl   $0x1,-0x4(%rbp)
jmp    13e8 <main+0x268>
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    123f <main+0xbf>
mov    -0x28(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x141(%rbp)
jne    1276 <main+0xf6>
xor    %eax,%eax
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x142(%rbp)
jne    126a <main+0xea>
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x142(%rbp)
mov    -0x142(%rbp),%al
mov    %al,-0x141(%rbp)
mov    -0x141(%rbp),%al
test   $0x1,%al
jne    1289 <main+0x109>
jmp    13d0 <main+0x250>
lea    -0x18(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x28(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <select@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    13ae <main+0x22e>
cmpl   $0x0,-0x30(%rbp)
jne    133d <main+0x1bd>
mov    -0x28(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     133d <main+0x1bd>
mov    -0x28(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    131f <main+0x19f>
movl   $0x1,-0x30(%rbp)
jmp    1338 <main+0x1b8>
lea    -0x140(%rbp),%rdi
call   1090 <atoi@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    133d <main+0x1bd>
cmpl   $0x0,-0x34(%rbp)
jne    13a9 <main+0x229>
mov    -0x2c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     13a9 <main+0x229>
mov    -0x2c(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    138b <main+0x20b>
movl   $0x1,-0x34(%rbp)
jmp    13a4 <main+0x224>
lea    -0x140(%rbp),%rdi
call   1090 <atoi@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    13a9 <main+0x229>
jmp    13cb <main+0x24b>
cmpl   $0x0,-0x14(%rbp)
jge    13c6 <main+0x246>
lea    0xc49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13cb <main+0x24b>
jmp    1214 <main+0x94>
mov    -0x24(%rbp),%esi
lea    0xc41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e40(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1090 <open@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
je     1348 <main+0x1b8>
mov    %eax,%r12d
mov    0x0(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1348 <main+0x1b8>
mov    %eax,%ebp
mov    %eax,%r15d
add    $0x1,%r15d
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0xc(%rsp),%rbx
xor    %r14d,%r14d
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
test   %r14d,%r14d
je     1230 <main+0xa0>
test   %r13d,%r13d
jne    1334 <main+0x1a4>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
jne    1240 <main+0xb0>
jmp    1334 <main+0x1a4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1205 <main+0x75>
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   10b0 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <FD_SET@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
test   %eax,%eax
jg     1286 <main+0xf6>
jns    1200 <main+0x70>
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
jmp    1200 <main+0x70>
test   %r14d,%r14d
je     12d9 <main+0x149>
mov    $0x1,%r14d
test   %r13d,%r13d
mov    $0x1,%r13d
jne    1200 <main+0x70>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
mov    $0x0,%r13d
test   %rax,%rax
je     1200 <main+0x70>
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
mov    $0xff,%edx
call   1060 <read@plt>
mov    $0x1,%r13d
test   %eax,%eax
jne    131b <main+0x18b>
jmp    1200 <main+0x70>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1291 <main+0x101>
mov    %r12d,%edi
lea    0x10(%rsp),%rsi
mov    $0xff,%edx
call   1060 <read@plt>
test   %eax,%eax
je     128b <main+0xfb>
lea    0x10(%rsp),%rdi
call   10a0 <atoi@plt>
mov    (%rsp),%rcx
add    %eax,%ecx
mov    %rcx,(%rsp)
jmp    1291 <main+0x101>
lea    0x10(%rsp),%rdi
call   10a0 <atoi@plt>
mov    (%rsp),%rcx
add    %eax,%ecx
mov    %rcx,(%rsp)
jmp    11f7 <main+0x67>
lea    0xccd(%rip),%rdi
xor    %ebx,%ebx
mov    (%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"in1\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"in2\00"
@.str.2 = [19 x i8] c"Error on select()\0A\00"
@.str.3 = [4 x i8] c"%d\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %11
%18 = icmp eq i32 -1, %17
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 1, i32* %3
br label %110
20: ; preds = %2
store i32 0, i32* %13
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 %22, i32* %12
%23 = icmp eq i32 -1, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %3
br label %110
25: ; preds = %20
store i32 0, i32* %14
br label %26
26: ; preds = %106, %25
%27 = load i32, i32* %13
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %11
%31 = call i64 @FD_ISSET(i32 %30, i32* %7)
%32 = icmp ne i64 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %29, %26
%34 = load i32, i32* %14
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = load i32, i32* %12
%38 = call i64 @FD_ISSET(i32 %37, i32* %7)
%39 = icmp ne i64 %38, 0
br label %40
40: ; preds = %36, %33
%41 = phi i1 [ false, %33 ], [ %39, %36 ]
br label %42
42: ; preds = %40, %29
%43 = phi i1 [ true, %29 ], [ %41, %40 ]
br i1 %43, label %44, label %107
44: ; preds = %42
%45 = call i32 @FD_ZERO(i32* %7)
%46 = load i32, i32* %11
%47 = call i32 @FD_SET(i32 %46, i32* %7)
%48 = load i32, i32* %12
%49 = call i32 @FD_SET(i32 %48, i32* %7)
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
%52 = call i32 @select(i32 %51, i32* %7, i32* null, i32* null, i32* null)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %100
55: ; preds = %44
%56 = load i32, i32* %13
%57 = icmp ne i32 %56, 0
br i1 %57, label %77, label %58
58: ; preds = %55
%59 = load i32, i32* %11
%60 = call i64 @FD_ISSET(i32 %59, i32* %7)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %77
62: ; preds = %58
%63 = load i32, i32* %11
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %15, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 255)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = icmp eq i32 0, %66
br i1 %67, label %68, label %69
68: ; preds = %62
store i32 1, i32* %13
br label %76
69: ; preds = %62
%70 = getelementptr inbounds [255 x i8], [255 x i8]* %15, i64 0, i64 0
%71 = call i64 @atoi(i8* %70)
%72 = load i32, i32* %10
%73 = sext i32 %72 to i64
%74 = add nsw i64 %73, %71
%75 = trunc i64 %74 to i32
store i32 %75, i32* %10
br label %76
76: ; preds = %69, %68
br label %77
77: ; preds = %76, %58, %55
%78 = load i32, i32* %14
%79 = icmp ne i32 %78, 0
br i1 %79, label %99, label %80
80: ; preds = %77
%81 = load i32, i32* %12
%82 = call i64 @FD_ISSET(i32 %81, i32* %7)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %99
84: ; preds = %80
%85 = load i32, i32* %12
%86 = getelementptr inbounds [255 x i8], [255 x i8]* %15, i64 0, i64 0
%87 = call i32 @read(i32 %85, i8* %86, i32 255)
store i32 %87, i32* %6
%88 = load i32, i32* %6
%89 = icmp eq i32 0, %88
br i1 %89, label %90, label %91
90: ; preds = %84
store i32 1, i32* %14
br label %98
91: ; preds = %84
%92 = getelementptr inbounds [255 x i8], [255 x i8]* %15, i64 0, i64 0
%93 = call i64 @atoi(i8* %92)
%94 = load i32, i32* %10
%95 = sext i32 %94 to i64
%96 = add nsw i64 %95, %93
%97 = trunc i64 %96 to i32
store i32 %97, i32* %10
br label %98
98: ; preds = %91, %90
br label %99
99: ; preds = %98, %80, %77
br label %106
100: ; preds = %44
%101 = load i32, i32* %6
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %100
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %105
105: ; preds = %103, %100
br label %106
106: ; preds = %105, %99
br label %26
107: ; preds = %42
%108 = load i32, i32* %10
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %108)
store i32 0, i32* %3
br label %110
110: ; preds = %107, %24, %19
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
@.str = [4 x i8] c"in1\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"in2\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [18 x i8] c"Error on select()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %71, label %10
10: ; preds = %2
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %71, label %14
14: ; preds = %10
%15 = add nuw nsw i32 %12, 1
br label %16
16: ; preds = %51, %14
%17 = phi i32 [ 0, %14 ], [ %52, %51 ]
%18 = phi i32 [ 0, %14 ], [ %49, %51 ]
%19 = phi i32 [ 0, %14 ], [ %53, %51 ]
%20 = icmp eq i32 %18, 0
%21 = icmp eq i32 %19, 0
br label %22
22: ; preds = %66, %16
br i1 %20, label %23, label %26
23: ; preds = %22
%24 = call i64 @FD_ISSET(i32 %8, i32* %3)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23, %22
br i1 %21, label %27, label %69
27: ; preds = %26
%28 = call i64 @FD_ISSET(i32 %12, i32* %3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %69, label %30
30: ; preds = %23, %27
%31 = call i32 @FD_ZERO(i32* %3)
%32 = call i32 @FD_SET(i32 %8, i32* %3)
%33 = call i32 @FD_SET(i32 %12, i32* %3)
%34 = call i32 @select(i32 %15, i32* %3, i32* null, i32* null, i32* null)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %64
36: ; preds = %30
br i1 %20, label %37, label %47
37: ; preds = %36
%38 = call i64 @FD_ISSET(i32 %8, i32* %3)
%39 = icmp eq i64 %38, 0
br i1 %39, label %47, label %40
40: ; preds = %37
%41 = call i32 @read(i32 %8, i8* %6, i32 255)
%42 = icmp eq i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = call i64 @atoi(i8* %6)
%45 = trunc i64 %44 to i32
%46 = add i32 %17, %45
br label %47
47: ; preds = %40, %43, %37, %36
%48 = phi i32 [ %17, %36 ], [ %46, %43 ], [ %17, %37 ], [ %17, %40 ]
%49 = phi i32 [ 1, %36 ], [ 0, %43 ], [ 0, %37 ], [ 1, %40 ]
%50 = icmp eq i32 %19, 0
br i1 %50, label %54, label %51
51: ; preds = %47, %60, %54, %57
%52 = phi i32 [ %48, %57 ], [ %48, %54 ], [ %63, %60 ], [ %48, %47 ]
%53 = phi i32 [ 1, %57 ], [ 0, %54 ], [ 0, %60 ], [ 1, %47 ]
br label %16
54: ; preds = %47
%55 = call i64 @FD_ISSET(i32 %12, i32* %3)
%56 = icmp eq i64 %55, 0
br i1 %56, label %51, label %57
57: ; preds = %54
%58 = call i32 @read(i32 %12, i8* %6, i32 255)
%59 = icmp eq i32 %58, 0
br i1 %59, label %51, label %60
60: ; preds = %57
%61 = call i64 @atoi(i8* %6)
%62 = trunc i64 %61 to i32
%63 = add i32 %48, %62
br label %51
64: ; preds = %30
%65 = icmp slt i32 %34, 0
br i1 %65, label %67, label %66
66: ; preds = %64, %67
br label %22
67: ; preds = %64
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %66
69: ; preds = %26, %27
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %71
71: ; preds = %10, %2, %69
%72 = phi i32 [ 0, %69 ], [ 1, %2 ], [ 1, %10 ]
ret i32 %72
}