double g_vi(double bluechan, double greenchan, double redchan, double nirchan,
            double chan5chan, double chan7chan) {
  double result;
  if ((nirchan + redchan) == 0.0) {
    result = -1.0;
  } else {
    result = (-0.2848 * bluechan - 0.2435 * greenchan - 0.5436 * redchan +
              0.7243 * nirchan + 0.0840 * chan5chan - 0.1800 * chan7chan);
  }
  return result;
}


x86 assembly (clang, -O0):
<g_vi>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1151 <g_vi+0x51>
jp     1151 <g_vi+0x51>
movsd  0xee9(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11e3 <g_vi+0xe3>
movsd  -0x8(%rbp),%xmm0
movsd  0xeca(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe9e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe81(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0xe64(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe47(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_vi>:
movapd %xmm2,%xmm6
addsd  %xmm3,%xmm6
xorpd  %xmm7,%xmm7
ucomisd %xmm7,%xmm6
jne    111d <g_vi+0x1d>
jp     111d <g_vi+0x1d>
movsd  0xf14(%rip),%xmm0
ret
mulsd  0xedb(%rip),%xmm1
mulsd  0xedb(%rip),%xmm0
addsd  %xmm1,%xmm0
mulsd  0xed7(%rip),%xmm2
mulsd  0xed7(%rip),%xmm3
addsd  %xmm0,%xmm2
addsd  %xmm2,%xmm3
mulsd  0xecf(%rip),%xmm4
addsd  %xmm3,%xmm4
mulsd  0xecb(%rip),%xmm5
addsd  %xmm4,%xmm5
movapd %xmm5,%xmm0
ret

LLVM IR (-O0):
define double @g_vi(double %0, double %1, double %2, double %3, double %4, double %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
store double %5, double* %12
%14 = load double, double* %10
%15 = load double, double* %9
%16 = fadd double %14, %15
%17 = fcmp oeq double %16, 0.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %6
store double -1.000000e+00, double* %13
br label %33
19: ; preds = %6
%20 = load double, double* %7
%21 = load double, double* %8
%22 = fmul double 2.435000e-01, %21
%23 = fneg double %22
%24 = call double @llvm.fmuladd.f64(double -2.848000e-01, double %20, double %23)
%25 = load double, double* %9
%26 = call double @llvm.fmuladd.f64(double -5.436000e-01, double %25, double %24)
%27 = load double, double* %10
%28 = call double @llvm.fmuladd.f64(double 7.243000e-01, double %27, double %26)
%29 = load double, double* %11
%30 = call double @llvm.fmuladd.f64(double 8.400000e-02, double %29, double %28)
%31 = load double, double* %12
%32 = call double @llvm.fmuladd.f64(double -1.800000e-01, double %31, double %30)
store double %32, double* %13
br label %33
33: ; preds = %19, %18
%34 = load double, double* %13
ret double %34
}

LLVM IR (-O2):
define double @g_vi(double %0, double %1, double %2, double %3, double %4, double %5) {
%7 = fadd double %2, %3
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = fmul double %1, -2.435000e-01
%11 = tail call double @llvm.fmuladd.f64(double %0, double -2.848000e-01, double %10)
%12 = tail call double @llvm.fmuladd.f64(double %2, double -5.436000e-01, double %11)
%13 = tail call double @llvm.fmuladd.f64(double %3, double 7.243000e-01, double %12)
%14 = tail call double @llvm.fmuladd.f64(double %4, double 8.400000e-02, double %13)
%15 = tail call double @llvm.fmuladd.f64(double %5, double -1.800000e-01, double %14)
br label %16
16: ; preds = %6, %9
%17 = phi double [ %15, %9 ], [ -1.000000e+00, %6 ]
ret double %17
}