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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    return EXIT_FAILURE;
  }
  FILE *fin1;
  FILE *fin2;
  fin1 = fopen(argv[1], "r");
  if (fin1 == NULL) {
    return EXIT_FAILURE;
  }
  fin2 = fopen(argv[2], "r");
  if (fin2 == NULL) {
    fclose(fin1);
    return EXIT_FAILURE;
  }
  FILE *fout;
  fout = fopen(argv[3], "w");
  if (fout == NULL) {
    fclose(fin1);
    fclose(fin2);
    return EXIT_FAILURE;
  }
  int val1;
  int val2;
  int in1ok = 1;
  int in2ok = 1;
  while ((in1ok == 1) || (in2ok == 1)) {
    val1 = 0;
    val2 = 0;
    if (fscanf(fin1, "%d", &val1) != 1) {
      in1ok = 0;
    }
    if (fscanf(fin2, "%d", &val2) != 1) {
      in2ok = 0;
    }
    if ((in1ok == 1) || (in2ok == 1)) {
      fprintf(fout, "%d\n", val1 + val2);
    }
  }
  fclose(fin1);
  fclose(fin2);
  fclose(fout);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1171 <main+0x31>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <main+0x65>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <main+0xa2>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe11(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1228 <main+0xe8>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130b <main+0x1cb>
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x34(%rbp)
mov    %al,-0x39(%rbp)
je     124f <main+0x10f>
cmpl   $0x1,-0x38(%rbp)
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    125f <main+0x11f>
jmp    12e4 <main+0x1a4>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd8c(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     1291 <main+0x151>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd68(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     12b5 <main+0x175>
movl   $0x0,-0x38(%rbp)
cmpl   $0x1,-0x34(%rbp)
je     12c9 <main+0x189>
cmpl   $0x1,-0x38(%rbp)
jne    12df <main+0x19f>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
add    -0x30(%rbp),%edx
lea    0xd2d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1236 <main+0xf6>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
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
cmp    $0x3,%edi
jle    126d <main+0x12d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     126d <main+0x12d>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1256 <main+0x116>
mov    0x18(%rbx),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     125b <main+0x11b>
mov    %rax,%r12
mov    $0x1,%r13d
lea    0xe47(%rip),%rbx
xor    %ebp,%ebp
mov    $0x1,%r14d
jmp    11e7 <main+0xa7>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edx
add    0xc(%rsp),%edx
mov    %r12,%rdi
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
lea    0xc(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
cmovne %ebp,%r14d
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
lea    0x8(%rsp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
cmovne %ebp,%r13d
cmp    $0x1,%r14d
je     11d0 <main+0x90>
cmp    $0x1,%r13d
je     11d0 <main+0x90>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x2d84(%rip),%rax
jmp    1274 <main+0x134>
mov    %r15,%rdi
jmp    1268 <main+0x128>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EXIT_FAILURE
br label %57
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = load i32, i32* @EXIT_FAILURE
br label %57
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = tail call i32 @fclose(i32* %11)
%22 = load i32, i32* @EXIT_FAILURE
br label %57
23: ; preds = %15
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = tail call i32 @fclose(i32* %11)
%30 = tail call i32 @fclose(i32* %18)
%31 = load i32, i32* @EXIT_FAILURE
br label %57
32: ; preds = %23
%33 = bitcast i32* %3 to i8*
%34 = bitcast i32* %4 to i8*
br label %35
35: ; preds = %47, %32
%36 = phi i32 [ 1, %32 ], [ %43, %47 ]
%37 = phi i32 [ 1, %32 ], [ %40, %47 ]
store i32 0, i32* %3
store i32 0, i32* %4
%38 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%39 = icmp eq i32 %38, 1
%40 = select i1 %39, i32 %37, i32 0
%41 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%42 = icmp eq i32 %41, 1
%43 = select i1 %42, i32 %36, i32 0
%44 = icmp eq i32 %40, 1
%45 = icmp eq i32 %43, 1
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %47, label %52
47: ; preds = %35
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = add nsw i32 %49, %48
%51 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %35
52: ; preds = %35
%53 = call i32 @fclose(i32* %11)
%54 = call i32 @fclose(i32* %18)
%55 = call i32 @fclose(i32* %26)
%56 = load i32, i32* @EXIT_SUCCESS
br label %57
57: ; preds = %13, %20, %52, %28, %6
%58 = phi i32 [ %7, %6 ], [ %14, %13 ], [ %22, %20 ], [ %31, %28 ], [ %56, %52 ]
ret i32 %58
}