#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 EOF;
int fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ skipWord(int /*<<< orphan*/ *);
double mean(FILE *stream) {
  double l = 0;
  double average = 0;
  double d = 0;
  int test;
  while ((test = fscanf(stream, "%lf", &d)) != EOF) {
    if (!test) {
      skipWord(stream);
    } else {
      average += d;
      l++;
    }
  }
  average /= l;
  return average;
}


x86 assembly (clang, -O0):
<mean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%eax
je     11a8 <mean+0x88>
cmpl   $0x0,-0x24(%rbp)
jne    1182 <mean+0x62>
mov    -0x8(%rbp),%rdi
call   1040 <skipWord@plt>
jmp    11a3 <mean+0x83>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe67(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1144 <mean+0x24>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mean>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xed2(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1030 <fscanf@plt>
mov    0x2e99(%rip),%r12
cmp    (%r12),%eax
jne    115f <mean+0x3f>
movsd  0xea3(%rip),%xmm0
jmp    11d1 <mean+0xb1>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
lea    0xea1(%rip),%r14
lea    0x8(%rsp),%r15
xorpd  %xmm0,%xmm0
jmp    11b8 <mean+0x98>
nopw   0x0(%rax,%rax,1)
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
addsd  0xe6f(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fscanf@plt>
cmp    (%r12),%eax
movsd  0x10(%rsp),%xmm0
je     11cc <mean+0xac>
test   %eax,%eax
jne    1180 <mean+0x60>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <skipWord@plt>
jmp    119e <mean+0x7e>
divsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lf\00"
@EOF = global i32 0
define double @mean(i32* %0) {
%2 = alloca i32*
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32* %0, i32** %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
br label %7
7: ; preds = %24, %1
%8 = load i32*, i32** %2
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %5)
store i32 %9, i32* %6
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32*, i32** %2
%17 = call i32 @skipWord(i32* %16)
br label %24
18: ; preds = %12
%19 = load double, double* %5
%20 = load double, double* %4
%21 = fadd double %20, %19
store double %21, double* %4
%22 = load double, double* %3
%23 = fadd double %22, 1.000000e+00
store double %23, double* %3
br label %24
24: ; preds = %18, %15
br label %7
25: ; preds = %7
%26 = load double, double* %3
%27 = load double, double* %4
%28 = fdiv double %27, %26
store double %28, double* %4
%29 = load double, double* %4
ret double %29
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lf\00"
@EOF = global i32 0
define double @mean(i32* %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
%4 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %2)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %26, label %7
7: ; preds = %1, %18
%8 = phi i32 [ %21, %18 ], [ %4, %1 ]
%9 = phi double [ %20, %18 ], [ 0.000000e+00, %1 ]
%10 = phi double [ %19, %18 ], [ 0.000000e+00, %1 ]
%11 = icmp eq i32 %8, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @skipWord(i32* %0)
br label %18
14: ; preds = %7
%15 = load double, double* %2
%16 = fadd double %10, %15
%17 = fadd double %9, 1.000000e+00
br label %18
18: ; preds = %14, %12
%19 = phi double [ %16, %14 ], [ %10, %12 ]
%20 = phi double [ %17, %14 ], [ %9, %12 ]
%21 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %2)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %7
24: ; preds = %18
%25 = fdiv double %19, %20
br label %26
26: ; preds = %24, %1
%27 = phi double [ %25, %24 ], [ 0x7FF8000000000000, %1 ]
ret double %27
}