#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 */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long long);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int main(int argc, char **argv) {
  FILE *in = fopen(argv[1], "r");
  FILE *out = fopen(argv[2], "w");
  long long sum = 0;
  int current;
  while (EOF != fscanf(in, "%d", &current))
    sum += current;
  fprintf(out, "%lld\n", sum);
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     11c1 <main+0x91>
movslq -0x2c(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    117e <main+0x4e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%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    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xea3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,0x10(%rsp)
mov    0x2e78(%rip),%rbp
mov    0x0(%rbp),%rbx
lea    0xe89(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
call   1030 <fscanf@plt>
cmp    %rax,%rbx
jne    1191 <main+0x61>
xor    %ebx,%ebx
jmp    11bf <main+0x8f>
xor    %ebx,%ebx
lea    0xe6a(%rip),%r12
lea    0xc(%rsp),%r13
nop
movslq 0xc(%rsp),%rax
add    %rax,%rbx
mov    0x0(%rbp),%r14
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <fscanf@plt>
cmp    %rax,%r14
jne    11a0 <main+0x70>
lea    0xe41(%rip),%rsi
mov    0x10(%rsp),%rdi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"%lld\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 i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
store i64 0, i64* %8
br label %18
18: ; preds = %23, %2
%19 = load i64, i64* @EOF
%20 = load i32*, i32** %6
%21 = call i64 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%22 = icmp ne i64 %19, %21
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = load i64, i64* %8
%27 = add nsw i64 %26, %25
store i64 %27, i64* %8
br label %18
28: ; preds = %18
%29 = load i32*, i32** %7
%30 = load i64, i64* %8
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i64 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c"%lld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = bitcast i32* %3 to i8*
%11 = load i64, i64* @EOF
%12 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%13 = icmp eq i64 %11, %12
br i1 %13, label %22, label %14
14: ; preds = %2, %14
%15 = phi i64 [ %18, %14 ], [ 0, %2 ]
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = add nsw i64 %15, %17
%19 = load i64, i64* @EOF
%20 = call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %14
22: ; preds = %14, %2
%23 = phi i64 [ 0, %2 ], [ %18, %14 ]
%24 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %23)
ret i32 0
}