#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 log(double);
double sqrt(int);
double StabilityCorrection(double Z, double d, double TSurf, double Tair,
                           double Wind, double Z0) {
  double Correction;
  double Ri;
  double RiCr = 0.2;
  double RiLimit;
  Correction = 1.0;
  if (TSurf != Tair) {
    Ri = 9.81 * (Tair - TSurf) * (Z - d) /
         (((Tair + 273.15) + (TSurf + 273.15)) / 2.0 * Wind * Wind);
    RiLimit = (Tair + 273.15) / (((Tair + 273.15) + (TSurf + 273.15)) / 2.0 *
                                 (log((Z - d) / Z0) + 5));
    if (Ri > RiLimit)
      Ri = RiLimit;
    if (Ri > 0.0)
      Correction = (1 - Ri / RiCr) * (1 - Ri / RiCr);
    else {
      if (Ri < -0.5)
        Ri = -0.5;
      Correction = sqrt(1 - 16 * Ri);
    }
  }
  return Correction;
}


x86 assembly (clang, -O0):
<StabilityCorrection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
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  0xeba(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xea5(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    117b <StabilityCorrection+0x5b>
jp     117b <StabilityCorrection+0x5b>
jmp    1305 <StabilityCorrection+0x1e5>
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe93(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe71(%rip),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  0xe64(%rip),%xmm2
addsd  -0x18(%rbp),%xmm2
addsd  %xmm2,%xmm1
movsd  0xe4b(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe34(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe22(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe15(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdfc(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
call   1030 <log@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
add    $0x5,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1269 <StabilityCorrection+0x149>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12b5 <StabilityCorrection+0x195>
movsd  -0x40(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
movsd  0xd73(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  -0x40(%rbp),%xmm2
divsd  -0x48(%rbp),%xmm2
movsd  0xd5d(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1300 <StabilityCorrection+0x1e0>
movsd  0xd6b(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    12d5 <StabilityCorrection+0x1b5>
movsd  0xd58(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xd4e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd12(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
jmp    1305 <StabilityCorrection+0x1e5>
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StabilityCorrection>:
sub    $0x48,%rsp
ucomisd %xmm3,%xmm2
jne    1130 <StabilityCorrection+0x10>
jnp    11fe <StabilityCorrection+0xde>
movapd %xmm3,%xmm6
subsd  %xmm2,%xmm6
mulsd  0xec8(%rip),%xmm6
subsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpcklpd %xmm3,%xmm1
movapd %xmm0,%xmm3
mulpd  %xmm6,%xmm3
shufpd $0x2,0xee3(%rip),%xmm6
addpd  %xmm1,%xmm6
shufpd $0x2,%xmm6,%xmm3
movapd %xmm3,0x30(%rsp)
addsd  0xe9c(%rip),%xmm2
unpckhpd %xmm6,%xmm6
addsd  %xmm2,%xmm6
mulsd  0xe94(%rip),%xmm6
movapd %xmm6,0x20(%rsp)
mulsd  %xmm4,%xmm6
movapd %xmm6,0x10(%rsp)
divsd  %xmm5,%xmm0
movapd %xmm4,(%rsp)
call   1030 <log@plt>
add    $0x5,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd 0x10(%rsp),%xmm1
unpcklpd 0x20(%rsp),%xmm1
movapd (%rsp),%xmm2
unpcklpd %xmm0,%xmm2
mulpd  %xmm1,%xmm2
movapd 0x30(%rsp),%xmm1
divpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
minsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120b <StabilityCorrection+0xeb>
divsd  0xe43(%rip),%xmm0
addsd  0xe0b(%rip),%xmm0
mulsd  %xmm0,%xmm0
add    $0x48,%rsp
ret
movsd  0xdfa(%rip),%xmm0
add    $0x48,%rsp
ret
movsd  0xe0d(%rip),%xmm1
maxsd  %xmm0,%xmm1
mulsd  0xe09(%rip),%xmm1
addsd  0xdd9(%rip),%xmm1
cvttsd2si %xmm1,%edi
add    $0x48,%rsp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @StabilityCorrection(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
%14 = alloca double
%15 = alloca double
%16 = 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
store double 2.000000e-01, double* %15
store double 1.000000e+00, double* %13
%17 = load double, double* %9
%18 = load double, double* %10
%19 = fcmp une double %17, %18
br i1 %19, label %20, label %86
20: ; preds = %6
%21 = load double, double* %10
%22 = load double, double* %9
%23 = fsub double %21, %22
%24 = fmul double 9.810000e+00, %23
%25 = load double, double* %7
%26 = load double, double* %8
%27 = fsub double %25, %26
%28 = fmul double %24, %27
%29 = load double, double* %10
%30 = fadd double %29, 2.731500e+02
%31 = load double, double* %9
%32 = fadd double %31, 2.731500e+02
%33 = fadd double %30, %32
%34 = fdiv double %33, 2.000000e+00
%35 = load double, double* %11
%36 = fmul double %34, %35
%37 = load double, double* %11
%38 = fmul double %36, %37
%39 = fdiv double %28, %38
store double %39, double* %14
%40 = load double, double* %10
%41 = fadd double %40, 2.731500e+02
%42 = load double, double* %10
%43 = fadd double %42, 2.731500e+02
%44 = load double, double* %9
%45 = fadd double %44, 2.731500e+02
%46 = fadd double %43, %45
%47 = fdiv double %46, 2.000000e+00
%48 = load double, double* %7
%49 = load double, double* %8
%50 = fsub double %48, %49
%51 = load double, double* %12
%52 = fdiv double %50, %51
%53 = call i32 @log(double %52)
%54 = add nsw i32 %53, 5
%55 = sitofp i32 %54 to double
%56 = fmul double %47, %55
%57 = fdiv double %41, %56
store double %57, double* %16
%58 = load double, double* %14
%59 = load double, double* %16
%60 = fcmp ogt double %58, %59
br i1 %60, label %61, label %63
61: ; preds = %20
%62 = load double, double* %16
store double %62, double* %14
br label %63
63: ; preds = %61, %20
%64 = load double, double* %14
%65 = fcmp ogt double %64, 0.000000e+00
br i1 %65, label %66, label %76
66: ; preds = %63
%67 = load double, double* %14
%68 = load double, double* %15
%69 = fdiv double %67, %68
%70 = fsub double 1.000000e+00, %69
%71 = load double, double* %14
%72 = load double, double* %15
%73 = fdiv double %71, %72
%74 = fsub double 1.000000e+00, %73
%75 = fmul double %70, %74
store double %75, double* %13
br label %85
76: ; preds = %63
%77 = load double, double* %14
%78 = fcmp olt double %77, -5.000000e-01
br i1 %78, label %79, label %80
79: ; preds = %76
store double -5.000000e-01, double* %14
br label %80
80: ; preds = %79, %76
%81 = load double, double* %14
%82 = call double @llvm.fmuladd.f64(double -1.600000e+01, double %81, double 1.000000e+00)
%83 = fptosi double %82 to i32
%84 = call double @sqrt(i32 %83)
store double %84, double* %13
br label %85
85: ; preds = %80, %66
br label %86
86: ; preds = %85, %6
%87 = load double, double* %13
ret double %87
}

LLVM IR (-O2):
define double @StabilityCorrection(double %0, double %1, double %2, double %3, double %4, double %5) {
%7 = fcmp une double %2, %3
br i1 %7, label %8, label %48
8: ; preds = %6
%9 = fsub double %3, %2
%10 = fmul double %9, 9.810000e+00
%11 = fsub double %0, %1
%12 = insertelement <2 x double> poison, double %3, i64 1
%13 = insertelement <2 x double> %12, double %11, i64 0
%14 = insertelement <2 x double> <double poison, double 2.731500e+02>, double %10, i64 0
%15 = fmul <2 x double> %13, %14
%16 = fadd <2 x double> %13, %14
%17 = shufflevector <2 x double> %15, <2 x double> %16, <2 x i32> <i32 0, i32 3>
%18 = fadd double %2, 2.731500e+02
%19 = extractelement <2 x double> %16, i64 1
%20 = fadd double %18, %19
%21 = fmul double %20, 5.000000e-01
%22 = fmul double %21, %4
%23 = fdiv double %11, %5
%24 = tail call i32 @log(double %23)
%25 = add nsw i32 %24, 5
%26 = sitofp i32 %25 to double
%27 = insertelement <2 x double> poison, double %22, i64 0
%28 = insertelement <2 x double> %27, double %21, i64 1
%29 = insertelement <2 x double> poison, double %4, i64 0
%30 = insertelement <2 x double> %29, double %26, i64 1
%31 = fmul <2 x double> %28, %30
%32 = fdiv <2 x double> %17, %31
%33 = extractelement <2 x double> %32, i64 0
%34 = extractelement <2 x double> %32, i64 1
%35 = fcmp ogt double %33, %34
%36 = select i1 %35, double %34, double %33
%37 = fcmp ogt double %36, 0.000000e+00
br i1 %37, label %38, label %42
38: ; preds = %8
%39 = fdiv double %36, 2.000000e-01
%40 = fsub double 1.000000e+00, %39
%41 = fmul double %40, %40
br label %48
42: ; preds = %8
%43 = fcmp olt double %36, -5.000000e-01
%44 = select i1 %43, double -5.000000e-01, double %36
%45 = tail call double @llvm.fmuladd.f64(double %44, double -1.600000e+01, double 1.000000e+00)
%46 = fptosi double %45 to i32
%47 = tail call double @sqrt(i32 %46)
br label %48
48: ; preds = %38, %42, %6
%49 = phi double [ %41, %38 ], [ %47, %42 ], [ 1.000000e+00, %6 ]
ret double %49
}