#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 open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main() {
  int fd1 = open("in1", O_RDONLY, O_NONBLOCK);
  int fd2 = open("in2", O_RDONLY, O_NONBLOCK);
  int stop1 = 0, stop2 = 0;
  int sum = 0;
  for (;;) {
    fd_set fds;
    int maxfd;
    int res;
    char buf[1];
    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 && buf[0] != '\n') {
        int t;
        sscanf(buf, "%d", &t);
        sum += t;
      } else if (res == 0) {
        stop1 = 1;
      }
    }
    if (FD_ISSET(fd2, &fds)) {
      res = read(fd2, buf, sizeof(buf));
      if (res > 0 && buf[0] != '\n') {
        int t;
        sscanf(buf, "%d", &t);
        sum += t;
      } else if (res == 0) {
        stop2 = 1;
      }
    }
    if (stop1 == 1 && stop2 == 1) {
      break;
    }
  }
  printf("%d\n", sum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
lea    0xe58(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
lea    0xe3b(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    121e <main+0x9e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1224 <main+0xa4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12c2 <main+0x142>
mov    -0x8(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    12a7 <main+0x127>
movsbl -0x25(%rbp),%eax
cmp    $0xa,%eax
je     12a7 <main+0x127>
lea    -0x25(%rbp),%rdi
lea    0xd78(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x2c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    12bd <main+0x13d>
cmpl   $0x0,-0x24(%rbp)
jne    12b8 <main+0x138>
movl   $0x1,-0x10(%rbp)
jmp    12bd <main+0x13d>
jmp    12c2 <main+0x142>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1340 <main+0x1c0>
mov    -0xc(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1325 <main+0x1a5>
movsbl -0x25(%rbp),%eax
cmp    $0xa,%eax
je     1325 <main+0x1a5>
lea    -0x25(%rbp),%rdi
lea    0xcfa(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x30(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    133b <main+0x1bb>
cmpl   $0x0,-0x24(%rbp)
jne    1336 <main+0x1b6>
movl   $0x1,-0x14(%rbp)
jmp    133b <main+0x1bb>
jmp    1340 <main+0x1c0>
cmpl   $0x1,-0x10(%rbp)
jne    1359 <main+0x1d9>
cmpl   $0x1,-0x14(%rbp)
jne    1359 <main+0x1d9>
jmp    135e <main+0x1de>
jmp    11e6 <main+0x66>
mov    -0x18(%rbp),%esi
lea    0xca3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e4b(%rip),%rbx
mov    (%rbx),%esi
mov    0x2e4a(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xe58(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    (%rbx),%esi
mov    0x0(%rbp),%edx
lea    0xe48(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
cmp    %eax,%r15d
cmovg  %r15d,%eax
add    $0x1,%eax
mov    %eax,0x8(%rsp)
xor    %r12d,%r12d
lea    0x14(%rsp),%rbx
xor    %r13d,%r13d
xor    %r14d,%r14d
nop
mov    %rbx,%rdi
call   1060 <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    0x8(%rsp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <select@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     126b <main+0xeb>
mov    %r15d,%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1260 <main+0xe0>
cmpb   $0xa,0x7(%rsp)
je     1260 <main+0xe0>
lea    0x7(%rsp),%rdi
lea    0xdbf(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1080 <sscanf@plt>
add    0x10(%rsp),%r13d
jmp    126b <main+0xeb>
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
mov    $0x1,%eax
cmove  %eax,%r14d
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     12b1 <main+0x131>
mov    %ebp,%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    12c0 <main+0x140>
cmpb   $0xa,0x7(%rsp)
je     12c0 <main+0x140>
lea    0x7(%rsp),%rdi
lea    0xd66(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <sscanf@plt>
add    0xc(%rsp),%r13d
cmp    $0x1,%r14d
je     12d5 <main+0x155>
jmp    11e0 <main+0x60>
nopl   0x0(%rax)
test   %eax,%eax
mov    $0x1,%eax
cmove  %eax,%r12d
cmp    $0x1,%r14d
jne    11e0 <main+0x60>
cmp    $0x1,%r12d
jne    11e0 <main+0x60>
lea    0xd25(%rip),%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%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
@O_NONBLOCK = global i32 0
@.str.1 = [4 x i8] c"in2\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @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 i32
%10 = alloca [1 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = load i32, i32* @O_RDONLY
%14 = load i32, i32* @O_NONBLOCK
%15 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @O_NONBLOCK
%18 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
store i32 %18, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %19
19: ; preds = %97, %0
%20 = call i32 @FD_ZERO(i32* %7)
%21 = load i32, i32* %2
%22 = call i32 @FD_SET(i32 %21, i32* %7)
%23 = load i32, i32* %3
%24 = call i32 @FD_SET(i32 %23, i32* %7)
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = load i32, i32* %2
br label %32
30: ; preds = %19
%31 = load i32, i32* %3
br label %32
32: ; preds = %30, %28
%33 = phi i32 [ %29, %28 ], [ %31, %30 ]
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
%36 = call i32 @select(i32 %35, i32* %7, i32* null, i32* null, i32* null)
%37 = load i32, i32* %2
%38 = call i64 @FD_ISSET(i32 %37, i32* %7)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %63
40: ; preds = %32
%41 = load i32, i32* %2
%42 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 1)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %57
46: ; preds = %40
%47 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 10
br i1 %50, label %51, label %57
51: ; preds = %46
%52 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%53 = call i32 @sscanf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%54 = load i32, i32* %11
%55 = load i32, i32* %6
%56 = add nsw i32 %55, %54
store i32 %56, i32* %6
br label %62
57: ; preds = %46, %40
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
store i32 1, i32* %4
br label %61
61: ; preds = %60, %57
br label %62
62: ; preds = %61, %51
br label %63
63: ; preds = %62, %32
%64 = load i32, i32* %3
%65 = call i64 @FD_ISSET(i32 %64, i32* %7)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %90
67: ; preds = %63
%68 = load i32, i32* %3
%69 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%70 = call i32 @read(i32 %68, i8* %69, i32 1)
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %84
73: ; preds = %67
%74 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 10
br i1 %77, label %78, label %84
78: ; preds = %73
%79 = getelementptr inbounds [1 x i8], [1 x i8]* %10, i64 0, i64 0
%80 = call i32 @sscanf(i8* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%81 = load i32, i32* %12
%82 = load i32, i32* %6
%83 = add nsw i32 %82, %81
store i32 %83, i32* %6
br label %89
84: ; preds = %73, %67
%85 = load i32, i32* %9
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %84
store i32 1, i32* %5
br label %88
88: ; preds = %87, %84
br label %89
89: ; preds = %88, %78
br label %90
90: ; preds = %89, %63
%91 = load i32, i32* %4
%92 = icmp eq i32 %91, 1
br i1 %92, label %93, label %97
93: ; preds = %90
%94 = load i32, i32* %5
%95 = icmp eq i32 %94, 1
br i1 %95, label %96, label %97
96: ; preds = %93
br label %98
97: ; preds = %93, %90
br label %19
98: ; preds = %96
%99 = load i32, i32* %6
%100 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %99)
%101 = load i32, i32* %1
ret i32 %101
}

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.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1 x i8]
%3 = alloca i32
%4 = alloca i32
%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 = bitcast i32* %1 to i8*
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%13 = icmp sgt i32 %7, %10
%14 = select i1 %13, i32 %7, i32 %10
%15 = add nsw i32 %14, 1
%16 = bitcast i32* %3 to i8*
%17 = bitcast i32* %4 to i8*
br label %18
18: ; preds = %59, %0
%19 = phi i32 [ 0, %0 ], [ %60, %59 ]
%20 = phi i32 [ 0, %0 ], [ %61, %59 ]
%21 = phi i32 [ 0, %0 ], [ %43, %59 ]
%22 = call i32 @FD_ZERO(i32* %1)
%23 = call i32 @FD_SET(i32 %7, i32* %1)
%24 = call i32 @FD_SET(i32 %10, i32* %1)
%25 = call i32 @select(i32 %15, i32* %1, i32* null, i32* null, i32* null)
%26 = call i64 @FD_ISSET(i32 %7, i32* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %41, label %28
28: ; preds = %18
%29 = call i32 @read(i32 %7, i8* %12, i32 1)
%30 = icmp sgt i32 %29, 0
%31 = load i8, i8* %12
%32 = icmp ne i8 %31, 10
%33 = select i1 %30, i1 %32, i1 false
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%36 = load i32, i32* %3
%37 = add nsw i32 %36, %20
br label %41
38: ; preds = %28
%39 = icmp eq i32 %29, 0
%40 = select i1 %39, i32 1, i32 %21
br label %41
41: ; preds = %38, %34, %18
%42 = phi i32 [ %37, %34 ], [ %20, %18 ], [ %20, %38 ]
%43 = phi i32 [ %21, %34 ], [ %21, %18 ], [ %40, %38 ]
%44 = call i64 @FD_ISSET(i32 %10, i32* %1)
%45 = icmp eq i64 %44, 0
br i1 %45, label %59, label %46
46: ; preds = %41
%47 = call i32 @read(i32 %10, i8* %12, i32 1)
%48 = icmp sgt i32 %47, 0
%49 = load i8, i8* %12
%50 = icmp ne i8 %49, 10
%51 = select i1 %48, i1 %50, i1 false
br i1 %51, label %52, label %56
52: ; preds = %46
%53 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%54 = load i32, i32* %4
%55 = add nsw i32 %54, %42
br label %59
56: ; preds = %46
%57 = icmp eq i32 %47, 0
%58 = select i1 %57, i32 1, i32 %19
br label %59
59: ; preds = %56, %52, %41
%60 = phi i32 [ %19, %52 ], [ %19, %41 ], [ %58, %56 ]
%61 = phi i32 [ %55, %52 ], [ %42, %41 ], [ %42, %56 ]
%62 = icmp eq i32 %43, 1
%63 = icmp eq i32 %60, 1
%64 = select i1 %62, i1 %63, i1 false
br i1 %64, label %65, label %18
65: ; preds = %59
%66 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %61)
ret i32 0
}