#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 sqrt(int);
double msa_vi(double redchan, double nirchan) {
  double result;
  if ((nirchan + redchan) == 0.0) {
    result = -1.0;
  } else {
    result = (1 / 2) *
             (2 * (nirchan + 1) - sqrt((2 * nirchan + 1) * (2 * nirchan + 1)) -
              (8 * (nirchan - redchan)));
  }
  return result;
}


x86 assembly (clang, -O0):
<msa_vi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1151 <msa_vi+0x41>
jp     1151 <msa_vi+0x41>
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e8 <msa_vi+0xd8>
movsd  0xeaf(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe94(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe7f(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movsd  -0x20(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
movsd  0xe2c(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msa_vi>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
addsd  %xmm1,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm3
jne    1135 <msa_vi+0x25>
jp     1135 <msa_vi+0x25>
movsd  0xed0(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  0xecb(%rip),%xmm2
movapd %xmm1,%xmm3
addsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm1
cvttsd2si %xmm1,%edi
movsd  %xmm0,0x8(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm2
addsd  %xmm2,%xmm2
subsd  %xmm1,%xmm2
subsd  0x8(%rsp),%xmm0
mulsd  0xe78(%rip),%xmm0
addsd  %xmm2,%xmm0
mulsd  0xe74(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @msa_vi(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %4
%7 = load double, double* %3
%8 = fadd double %6, %7
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %2
store double -1.000000e+00, double* %5
br label %29
11: ; preds = %2
%12 = load double, double* %4
%13 = fadd double %12, 1.000000e+00
%14 = load double, double* %4
%15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double 1.000000e+00)
%16 = load double, double* %4
%17 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %16, double 1.000000e+00)
%18 = fmul double %15, %17
%19 = fptosi double %18 to i32
%20 = call i32 @sqrt(i32 %19)
%21 = sitofp i32 %20 to double
%22 = fneg double %21
%23 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %13, double %22)
%24 = load double, double* %4
%25 = load double, double* %3
%26 = fsub double %24, %25
%27 = call double @llvm.fmuladd.f64(double -8.000000e+00, double %26, double %23)
%28 = fmul double 0.000000e+00, %27
store double %28, double* %5
br label %29
29: ; preds = %11, %10
%30 = load double, double* %5
ret double %30
}

LLVM IR (-O2):
define double @msa_vi(double %0, double %1) {
%3 = fadd double %0, %1
%4 = fcmp oeq double %3, 0.000000e+00
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = fadd double %1, 1.000000e+00
%7 = tail call double @llvm.fmuladd.f64(double %1, double 2.000000e+00, double 1.000000e+00)
%8 = fmul double %7, %7
%9 = fptosi double %8 to i32
%10 = tail call i32 @sqrt(i32 %9)
%11 = sitofp i32 %10 to double
%12 = fneg double %11
%13 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double %12)
%14 = fsub double %1, %0
%15 = tail call double @llvm.fmuladd.f64(double %14, double -8.000000e+00, double %13)
%16 = fmul double %15, 0.000000e+00
br label %17
17: ; preds = %2, %5
%18 = phi double [ %16, %5 ], [ -1.000000e+00, %2 ]
ret double %18
}