double FindMaxDouble(double a[]) {
  double maxdouble = 0;
  for (int i = 0; i < sizeof(a); i++) {
    if (a[i] > maxdouble)
      maxdouble = a[i];
  }
  return maxdouble;
}


x86 assembly (clang, -O0):
<FindMaxDouble>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x8,%rax
jae    1162 <FindMaxDouble+0x62>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    114f <FindMaxDouble+0x4f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1154 <FindMaxDouble+0x54>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1117 <FindMaxDouble+0x17>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindMaxDouble>:
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
xorpd  %xmm2,%xmm2
maxsd  %xmm2,%xmm0
maxsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
maxsd  %xmm1,%xmm0
movsd  0x18(%rdi),%xmm1
maxsd  %xmm0,%xmm1
movsd  0x20(%rdi),%xmm0
maxsd  %xmm1,%xmm0
movsd  0x28(%rdi),%xmm1
maxsd  %xmm0,%xmm1
movsd  0x30(%rdi),%xmm2
maxsd  %xmm1,%xmm2
movsd  0x38(%rdi),%xmm0
maxsd  %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @FindMaxDouble(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 = %24, %1
%6 = load i32, i32* %4
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, 8
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = load double*, double** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %10, i64 %12
%14 = load double, double* %13
%15 = load double, double* %3
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load double*, double** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
store double %22, double* %3
br label %23
23: ; preds = %17, %9
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %5
27: ; preds = %5
%28 = load double, double* %3
ret double %28
}

LLVM IR (-O2):
define double @FindMaxDouble(double* nocapture %0) {
%2 = load double, double* %0
%3 = fcmp ogt double %2, 0.000000e+00
%4 = select i1 %3, double %2, double 0.000000e+00
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = fcmp ogt double %6, %4
%8 = select i1 %7, double %6, double %4
%9 = getelementptr inbounds double, double* %0, i64 2
%10 = load double, double* %9
%11 = fcmp ogt double %10, %8
%12 = select i1 %11, double %10, double %8
%13 = getelementptr inbounds double, double* %0, i64 3
%14 = load double, double* %13
%15 = fcmp ogt double %14, %12
%16 = select i1 %15, double %14, double %12
%17 = getelementptr inbounds double, double* %0, i64 4
%18 = load double, double* %17
%19 = fcmp ogt double %18, %16
%20 = select i1 %19, double %18, double %16
%21 = getelementptr inbounds double, double* %0, i64 5
%22 = load double, double* %21
%23 = fcmp ogt double %22, %20
%24 = select i1 %23, double %22, double %20
%25 = getelementptr inbounds double, double* %0, i64 6
%26 = load double, double* %25
%27 = fcmp ogt double %26, %24
%28 = select i1 %27, double %26, double %24
%29 = getelementptr inbounds double, double* %0, i64 7
%30 = load double, double* %29
%31 = fcmp ogt double %30, %28
%32 = select i1 %31, double %30, double %28
ret double %32
}