#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ stderr;
int main() {
  FILE *in, *out;
  double value, sum = 0.0;
  int count = 0;
  if ((in = fopen("app3.in", "r")) != NULL) {
    while (fscanf(in, "%le", &value) != EOF) {
      sum += value;
      count++;
    }
    fclose(in);
    if ((out = fopen("app3.out", "w")) != NULL) {
      fprintf(out, "%le", sum / count);
    } else {
      fprintf(stderr, "Failed to open output file\n");
      exit(2);
    }
    fclose(out);
    return 1;
  } else {
    fprintf(stderr, "Failed to open intput file\n");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe8b(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     125b <main+0x10b>
jmp    1194 <main+0x44>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
je     11d5 <main+0x85>
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1194 <main+0x44>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe29(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1226 <main+0xd6>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdf0(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
jmp    1247 <main+0xf7>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe9d(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1255 <main+0x105>
mov    %rax,%rbx
lea    0xe88(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e52(%rip),%r12
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
cmp    (%r12),%rax
je     11f0 <main+0xa0>
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
lea    0xe59(%rip),%r14
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
movsd  0x8(%rsp),%xmm0
cmp    (%r12),%rax
jne    11c0 <main+0x70>
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe03(%rip),%rdi
lea    0xe05(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1267 <main+0x117>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
divsd  0x18(%rsp),%xmm0
lea    0xdd8(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
jmp    1277 <main+0x127>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"app3.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%le\00"
@EOF = global i64 0
@.str.3 = [9 x i8] c"app3.out\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"Failed to open output file\0A\00"
@.str.6 = [28 x i8] c"Failed to open intput file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %5
store i32 0, i32* %6
%7 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %41
9: ; preds = %0
br label %10
10: ; preds = %15, %9
%11 = load i32*, i32** %2
%12 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %4)
%13 = load i64, i64* @EOF
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load double, double* %4
%17 = load double, double* %5
%18 = fadd double %17, %16
store double %18, double* %5
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %10
21: ; preds = %10
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
%24 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %3
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %34
26: ; preds = %21
%27 = load i32*, i32** %3
%28 = ptrtoint i32* %27 to i32
%29 = load double, double* %5
%30 = load i32, i32* %6
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %32)
br label %38
34: ; preds = %21
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %26
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
ret i32 1
41: ; preds = %0
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%44 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"app3.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%le\00"
@EOF = global i64 0
@.str.3 = [9 x i8] c"app3.out\00"
@.str.4 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"Failed to open output file\0A\00"
@.str.6 = [28 x i8] c"Failed to open intput file\0A\00"
define i32 @main() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %36, label %5
5: ; preds = %0
%6 = call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %20, label %9
9: ; preds = %5, %9
%10 = phi i32 [ %14, %9 ], [ 0, %5 ]
%11 = phi double [ %13, %9 ], [ 0.000000e+00, %5 ]
%12 = load double, double* %1
%13 = fadd double %11, %12
%14 = add nuw nsw i32 %10, 1
%15 = call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %1)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %9
18: ; preds = %9
%19 = sitofp i32 %14 to double
br label %20
20: ; preds = %18, %5
%21 = phi double [ 0.000000e+00, %5 ], [ %13, %18 ]
%22 = phi double [ 0.000000e+00, %5 ], [ %19, %18 ]
%23 = call i32 @fclose(i32* %3)
%24 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = ptrtoint i32* %24 to i64
%28 = trunc i64 %27 to i32
%29 = fdiv double %21, %22
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %29)
%31 = call i32 @fclose(i32* %24)
ret i32 1
32: ; preds = %20
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %0
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%39 = tail call i32 @exit(i32 2)
unreachable
}