#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int main() {
  FILE *f1;
  f1 = fopen("5-DATA", "r");
  int a, sum = 0;
  while (fscanf(f1, "%d", &a) != EOF)
    sum += a;
  fclose(f1);
  f1 = fopen("5-DATA", "a");
  fprintf(f1, " \n %d", sum);
  fclose(f1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
je     119f <main+0x5f>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    116d <main+0x2d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe51(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xea4(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e6a(%rip),%r13
xor    %ebx,%ebx
cmp    0x0(%r13),%rax
je     11b8 <main+0x78>
xor    %ebx,%ebx
lea    0xe7f(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    0xc(%rsp),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    11a0 <main+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe39(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe2e(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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