#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*/ feof(int /*<<< orphan*/ *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, double *);
double sum(FILE *stream) {
  double sum = 0.;
  double number = 0.;
  while (!feof(stream)) {
    sum = sum + number;
    if (fscanf(stream, "%lf", &number) != EOF) {
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115a <sum+0x3a>
jmp    1197 <sum+0x77>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <fscanf@plt>
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     1192 <sum+0x72>
jmp    1192 <sum+0x72>
jmp    113c <sum+0x1c>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,(%rsp)
call   1040 <feof@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
jne    11ab <sum+0x8b>
lea    0xeb8(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1030 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <feof@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
jne    11ab <sum+0x8b>
xorpd  %xmm0,%xmm0
lea    0xe92(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <feof@plt>
movsd  0x8(%rsp),%xmm0
test   %eax,%eax
je     1180 <sum+0x60>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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