#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 */

/* Variables and functions */
int /*<<< orphan*/ isnan(double);
double sum(double in[]) {
  double out = 0;
  for (int i = 0; !isnan(in[i]); i++)
    out += in[i];
  return out;
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1152 <sum+0x42>
jmp    1177 <sum+0x67>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <sum+0x1b>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
call   1030 <isnan@plt>
xorpd  %xmm0,%xmm0
test   %eax,%eax
jne    1162 <sum+0x52>
add    $0x8,%rbx
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addsd  -0x8(%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm0
call   1030 <isnan@plt>
movsd  0x8(%rsp),%xmm0
add    $0x8,%rbx
test   %eax,%eax
je     1140 <sum+0x30>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @sum(double* %0) {
%2 = alloca double*
%3 = alloca double
%4 = alloca i32
store double* %0, double** %2
store double 0.000000e+00, double* %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load double*, double** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds double, double* %6, i64 %8
%10 = load double, double* %9
%11 = call i32 @isnan(double %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %25
14: ; preds = %5
%15 = load double*, double** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double, double* %3
%21 = fadd double %20, %19
store double %21, double* %3
br label %22
22: ; preds = %14
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %5
%26 = load double, double* %3
ret double %26
}

LLVM IR (-O2):
define double @sum(double* nocapture %0) {
%2 = load double, double* %0
%3 = tail call i32 @isnan(double %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %7, %1
%6 = phi double [ 0.000000e+00, %1 ], [ %12, %7 ]
ret double %6
7: ; preds = %1, %7
%8 = phi i64 [ %13, %7 ], [ 0, %1 ]
%9 = phi double* [ %14, %7 ], [ %0, %1 ]
%10 = phi double [ %12, %7 ], [ 0.000000e+00, %1 ]
%11 = load double, double* %9
%12 = fadd double %10, %11
%13 = add nuw nsw i64 %8, 1
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = tail call i32 @isnan(double %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %7, label %5
}