#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*/ buf;

/* 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_NONBLOCK;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(int argc, char const *argv[]) {
  int fd1 = open("in1", O_RDONLY, O_NONBLOCK);
  int fd2 = open("in2", O_RDONLY, O_NONBLOCK);
  int sum = 0;
  if (fd1 < 0) {
    printf("In1 does not exist\n");
  }
  if (fd2 < 0) {
    printf("In2 does not exist\n");
  }
  while ((fd1 > 0) || (fd2 > 0)) {
    fd_set fds;
    int maxfd;
    int res;
    char buf[256];
    int num1, num2;
    FD_ZERO(&fds);
    FD_SET(fd1, &fds);
    FD_SET(fd2, &fds);
    maxfd = fd1 > fd2 ? fd1 : fd2;
    select(maxfd + 1, &fds, NULL, NULL, NULL);
    if (FD_ISSET(fd1, &fds)) {
      res = read(fd1, buf, sizeof(buf));
      if (res > 0) {
        num1 = atoi(buf);
      }
    }
    if (FD_ISSET(fd2, &fds)) {
      res = read(fd2, buf, sizeof(buf));
      if (res > 0) {
        num2 = atoi(buf);
      }
    }
    sum = sum + num1 + num2;
  }
  printf("%d\n", sum);
  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)
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
lea    0xe4e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
lea    0xe31(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11fa <main+0x7a>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jge    1212 <main+0x92>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1217 <main+0x97>
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x139(%rbp)
jg     1236 <main+0xb6>
cmpl   $0x0,-0x18(%rbp)
setg   %al
mov    %al,-0x139(%rbp)
mov    -0x139(%rbp),%al
test   $0x1,%al
jne    1249 <main+0xc9>
jmp    1363 <main+0x1e3>
lea    -0x20(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1284 <main+0x104>
mov    -0x14(%rbp),%eax
mov    %eax,-0x140(%rbp)
jmp    128d <main+0x10d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x140(%rbp)
mov    -0x140(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <select@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12fe <main+0x17e>
mov    -0x14(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    12f9 <main+0x179>
lea    -0x130(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x134(%rbp)
jmp    12fe <main+0x17e>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     134c <main+0x1cc>
mov    -0x18(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    1347 <main+0x1c7>
lea    -0x130(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x138(%rbp)
jmp    134c <main+0x1cc>
mov    -0x1c(%rbp),%eax
add    -0x134(%rbp),%eax
add    -0x138(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1217 <main+0x97>
mov    -0x1c(%rbp),%esi
lea    0xcc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    0x2e4a(%rip),%rbx
mov    (%rbx),%esi
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xe57(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
lea    0xe47(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
test   %r15d,%r15d
js     11d4 <main+0x54>
test   %ebp,%ebp
js     11e4 <main+0x64>
test   %r15d,%r15d
jle    11f5 <main+0x75>
jmp    121b <main+0x9b>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jns    11cd <main+0x4d>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
test   %r15d,%r15d
jg     121b <main+0x9b>
test   %ebp,%ebp
jg     121b <main+0x9b>
lea    0xe08(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    %ebp,%r15d
mov    %ebp,%r14d
cmovg  %r15d,%r14d
add    $0x1,%r14d
lea    0xc(%rsp),%rbx
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10a0 <FD_SET@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10a0 <FD_SET@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     128f <main+0x10f>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1240 <main+0xc0>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
jmp    1240 <main+0xc0>

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

LLVM IR (-O2):
@.str = [4 x i8] c"in1\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [4 x i8] c"in2\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [19 x i8] c"In2 does not exist\00"
@str.5 = [19 x i8] c"In1 does not exist\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = tail call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = load i32, i32* @O_RDONLY
%9 = load i32, i32* @O_NONBLOCK
%10 = tail call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9)
%11 = icmp slt i32 %7, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = icmp slt i32 %10, 0
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = icmp sgt i32 %7, 0
%20 = icmp sgt i32 %10, 0
%21 = or i1 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = bitcast i32* %3 to i8*
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = icmp sgt i32 %7, %10
%26 = select i1 %25, i32 %7, i32 %10
%27 = add nsw i32 %26, 1
br label %28
28: ; preds = %42, %22
%29 = call i32 @FD_ZERO(i32* %3)
%30 = call i32 @FD_SET(i32 %7, i32* %3)
%31 = call i32 @FD_SET(i32 %10, i32* %3)
%32 = call i32 @select(i32 %27, i32* %3, i32* null, i32* null, i32* null)
%33 = call i64 @FD_ISSET(i32 %7, i32* %3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 @read(i32 %7, i8* %24, i32 256)
br label %37
37: ; preds = %35, %28
%38 = call i64 @FD_ISSET(i32 %10, i32* %3)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = call i32 @read(i32 %10, i8* %24, i32 256)
br label %42
42: ; preds = %40, %37
br label %28
43: ; preds = %18
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 0)
ret i32 0
}