double calc_rc(double rs, double net_short, float RGL, double tair, double vpd,
               double lai, double gsm_inv, char ref_crop) {
  double f;
  double DAYfactor;
  double Tfactor;
  double vpdfactor;
  double rc;
  if (rs == 0) {
    rc = 0;
  } else if (lai == 0) {
    rc = 5000;
  } else if (ref_crop) {
    rc = rs / (lai * 0.5);
    rc = (rc > 5000) ? 5000 : rc;
  } else {
    if (rs > 0.) {
      f = net_short / RGL;
      DAYfactor = (1. + f) / (f + rs / 5000);
    } else
      DAYfactor = 1.;
    Tfactor = .08 * tair - 0.0016 * tair * tair;
    Tfactor = (Tfactor <= 0.0) ? 1e-10 : Tfactor;
    vpdfactor = 1 - vpd / 4000;
    vpdfactor = (vpdfactor < 0.1) ? 0.1 : vpdfactor;
    rc = rs / (lai * gsm_inv * Tfactor * vpdfactor) * DAYfactor;
    rc = (rc > 5000) ? 5000 : rc;
  }
  return rc;
}


x86 assembly (clang, -O0):
<calc_rc>:
push   %rbp
mov    %rsp,%rbp
push   %rax
mov    %dil,%al
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  %xmm6,-0x38(%rbp)
mov    %al,-0x39(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1153 <calc_rc+0x53>
jp     1153 <calc_rc+0x53>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1398 <calc_rc+0x298>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117d <calc_rc+0x7d>
jp     117d <calc_rc+0x7d>
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1393 <calc_rc+0x293>
cmpb   $0x0,-0x39(%rbp)
je     11e4 <calc_rc+0xe4>
movsd  -0x8(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  0xe59(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cb <calc_rc+0xcb>
movsd  0xe47(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    11d5 <calc_rc+0xd5>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    138e <calc_rc+0x28e>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1242 <calc_rc+0x142>
movsd  -0x10(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdeb(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movsd  0xddc(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    124f <calc_rc+0x14f>
movsd  0xdb6(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdbc(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xd8b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x58(%rbp),%xmm0
jb     12b2 <calc_rc+0x1b2>
movsd  0xd78(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    12bc <calc_rc+0x1bc>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xd5d(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd21(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xd38(%rip),%xmm0
ucomisd -0x60(%rbp),%xmm0
jbe    130d <calc_rc+0x20d>
movsd  0xd25(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    1317 <calc_rc+0x217>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  0xcb3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1374 <calc_rc+0x274>
movsd  0xca1(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
jmp    1381 <calc_rc+0x281>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x68(%rbp)
jmp    1393 <calc_rc+0x293>
jmp    1398 <calc_rc+0x298>
movsd  -0x68(%rbp),%xmm0
add    $0x8,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_rc>:
xorpd  %xmm7,%xmm7
ucomisd %xmm7,%xmm0
jne    1111 <calc_rc+0x11>
jp     1111 <calc_rc+0x11>
movapd %xmm7,%xmm0
ret
xorpd  %xmm7,%xmm7
ucomisd %xmm7,%xmm5
jne    1126 <calc_rc+0x26>
jp     1126 <calc_rc+0x26>
movsd  0xedb(%rip),%xmm0
ret
test   %dil,%dil
je     113c <calc_rc+0x3c>
mulsd  0xed5(%rip),%xmm5
divsd  %xmm5,%xmm0
jmp    11ee <calc_rc+0xee>
xorpd  %xmm8,%xmm8
ucomisd %xmm8,%xmm0
jbe    117c <calc_rc+0x7c>
cvtss2sd %xmm2,%xmm2
movapd %xmm0,%xmm7
unpcklpd %xmm1,%xmm7
movaps 0xee5(%rip),%xmm1
movlhps %xmm2,%xmm1
divpd  %xmm1,%xmm7
movapd %xmm7,%xmm1
unpckhpd %xmm7,%xmm1
addsd  %xmm1,%xmm7
addsd  0xe9a(%rip),%xmm1
divsd  %xmm7,%xmm1
jmp    1184 <calc_rc+0x84>
movsd  0xe8c(%rip),%xmm1
movsd  0xe8c(%rip),%xmm2
mulsd  %xmm3,%xmm2
mulsd  %xmm3,%xmm2
mulsd  0xe84(%rip),%xmm3
addsd  %xmm2,%xmm3
movapd %xmm3,%xmm2
cmplesd %xmm8,%xmm2
movsd  0xe76(%rip),%xmm7
andpd  %xmm2,%xmm7
andnpd %xmm3,%xmm2
divsd  0xe6e(%rip),%xmm4
orpd   %xmm2,%xmm7
addsd  0xe42(%rip),%xmm4
movsd  0xe62(%rip),%xmm2
maxsd  %xmm4,%xmm2
mulsd  %xmm6,%xmm5
mulsd  %xmm7,%xmm5
mulsd  %xmm2,%xmm5
divsd  %xmm5,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe0a(%rip),%xmm7
minsd  %xmm0,%xmm7
movapd %xmm7,%xmm0
ret

LLVM IR (-O0):
define double @calc_rc(double %0, double %1, float %2, double %3, double %4, double %5, double %6, i8 signext %7) {
%9 = alloca double
%10 = alloca double
%11 = alloca float
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i8
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
store double %0, double* %9
store double %1, double* %10
store float %2, float* %11
store double %3, double* %12
store double %4, double* %13
store double %5, double* %14
store double %6, double* %15
store i8 %7, i8* %16
%22 = load double, double* %9
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %8
store double 0.000000e+00, double* %21
br label %105
25: ; preds = %8
%26 = load double, double* %14
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %28, label %29
28: ; preds = %25
store double 5.000000e+03, double* %21
br label %104
29: ; preds = %25
%30 = load i8, i8* %16
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %29
%33 = load double, double* %9
%34 = load double, double* %14
%35 = fmul double %34, 5.000000e-01
%36 = fdiv double %33, %35
store double %36, double* %21
%37 = load double, double* %21
%38 = fcmp ogt double %37, 5.000000e+03
br i1 %38, label %39, label %40
39: ; preds = %32
br label %42
40: ; preds = %32
%41 = load double, double* %21
br label %42
42: ; preds = %40, %39
%43 = phi double [ 5.000000e+03, %39 ], [ %41, %40 ]
store double %43, double* %21
br label %103
44: ; preds = %29
%45 = load double, double* %9
%46 = fcmp ogt double %45, 0.000000e+00
br i1 %46, label %47, label %59
47: ; preds = %44
%48 = load double, double* %10
%49 = load float, float* %11
%50 = fpext float %49 to double
%51 = fdiv double %48, %50
store double %51, double* %17
%52 = load double, double* %17
%53 = fadd double 1.000000e+00, %52
%54 = load double, double* %17
%55 = load double, double* %9
%56 = fdiv double %55, 5.000000e+03
%57 = fadd double %54, %56
%58 = fdiv double %53, %57
store double %58, double* %18
br label %60
59: ; preds = %44
store double 1.000000e+00, double* %18
br label %60
60: ; preds = %59, %47
%61 = load double, double* %12
%62 = load double, double* %12
%63 = fmul double 1.600000e-03, %62
%64 = load double, double* %12
%65 = fmul double %63, %64
%66 = fneg double %65
%67 = call double @llvm.fmuladd.f64(double 8.000000e-02, double %61, double %66)
store double %67, double* %19
%68 = load double, double* %19
%69 = fcmp ole double %68, 0.000000e+00
br i1 %69, label %70, label %71
70: ; preds = %60
br label %73
71: ; preds = %60
%72 = load double, double* %19
br label %73
73: ; preds = %71, %70
%74 = phi double [ 1.000000e-10, %70 ], [ %72, %71 ]
store double %74, double* %19
%75 = load double, double* %13
%76 = fdiv double %75, 4.000000e+03
%77 = fsub double 1.000000e+00, %76
store double %77, double* %20
%78 = load double, double* %20
%79 = fcmp olt double %78, 1.000000e-01
br i1 %79, label %80, label %81
80: ; preds = %73
br label %83
81: ; preds = %73
%82 = load double, double* %20
br label %83
83: ; preds = %81, %80
%84 = phi double [ 1.000000e-01, %80 ], [ %82, %81 ]
store double %84, double* %20
%85 = load double, double* %9
%86 = load double, double* %14
%87 = load double, double* %15
%88 = fmul double %86, %87
%89 = load double, double* %19
%90 = fmul double %88, %89
%91 = load double, double* %20
%92 = fmul double %90, %91
%93 = fdiv double %85, %92
%94 = load double, double* %18
%95 = fmul double %93, %94
store double %95, double* %21
%96 = load double, double* %21
%97 = fcmp ogt double %96, 5.000000e+03
br i1 %97, label %98, label %99
98: ; preds = %83
br label %101
99: ; preds = %83
%100 = load double, double* %21
br label %101
101: ; preds = %99, %98
%102 = phi double [ 5.000000e+03, %98 ], [ %100, %99 ]
store double %102, double* %21
br label %103
103: ; preds = %101, %42
br label %104
104: ; preds = %103, %28
br label %105
105: ; preds = %104, %24
%106 = load double, double* %21
ret double %106
}

LLVM IR (-O2):
define double @calc_rc(double %0, double %1, float %2, double %3, double %4, double %5, double %6, i8 signext %7) {
%9 = fcmp oeq double %0, 0.000000e+00
br i1 %9, label %50, label %10
10: ; preds = %8
%11 = fcmp oeq double %5, 0.000000e+00
br i1 %11, label %50, label %12
12: ; preds = %10
%13 = icmp eq i8 %7, 0
br i1 %13, label %19, label %14
14: ; preds = %12
%15 = fmul double %5, 5.000000e-01
%16 = fdiv double %0, %15
%17 = fcmp ogt double %16, 5.000000e+03
%18 = select i1 %17, double 5.000000e+03, double %16
br label %50
19: ; preds = %12
%20 = fcmp ogt double %0, 0.000000e+00
br i1 %20, label %21, label %32
21: ; preds = %19
%22 = fpext float %2 to double
%23 = insertelement <2 x double> poison, double %0, i64 0
%24 = insertelement <2 x double> %23, double %1, i64 1
%25 = insertelement <2 x double> <double 5.000000e+03, double poison>, double %22, i64 1
%26 = fdiv <2 x double> %24, %25
%27 = extractelement <2 x double> %26, i64 1
%28 = fadd double %27, 1.000000e+00
%29 = extractelement <2 x double> %26, i64 0
%30 = fadd double %29, %27
%31 = fdiv double %28, %30
br label %32
32: ; preds = %19, %21
%33 = phi double [ %31, %21 ], [ 1.000000e+00, %19 ]
%34 = fmul double %3, -1.600000e-03
%35 = fmul double %34, %3
%36 = tail call double @llvm.fmuladd.f64(double %3, double 8.000000e-02, double %35)
%37 = fcmp ole double %36, 0.000000e+00
%38 = select i1 %37, double 1.000000e-10, double %36
%39 = fdiv double %4, 4.000000e+03
%40 = fsub double 1.000000e+00, %39
%41 = fcmp olt double %40, 1.000000e-01
%42 = select i1 %41, double 1.000000e-01, double %40
%43 = fmul double %5, %6
%44 = fmul double %43, %38
%45 = fmul double %42, %44
%46 = fdiv double %0, %45
%47 = fmul double %46, %33
%48 = fcmp ogt double %47, 5.000000e+03
%49 = select i1 %48, double 5.000000e+03, double %47
br label %50
50: ; preds = %10, %8, %32, %14
%51 = phi double [ %18, %14 ], [ %49, %32 ], [ 0.000000e+00, %8 ], [ 5.000000e+03, %10 ]
ret double %51
}