#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 */
double log(double);
double psim(double);
double bw(double hi, double molength, double z0) {
  double bw;
  double alpha = 0.12;
  double beta = 125;
  double z0_test = (alpha / beta) * hi;
  double b1 = -z0 / molength;
  if (z0 < z0_test)
    bw = -log(alpha) + psim(-alpha * hi / molength) - psim(-z0 / molength);
  else
    bw = log(hi / (beta * z0)) + psim(beta * b1) + psim(-z0 / molength);
  if (bw < 0.0)
    bw = 0;
  return (bw);
}


x86 assembly (clang, -O0):
<bw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    123d <bw+0x11d>
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <psim@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <psim@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    12b1 <bw+0x191>
movsd  -0x8(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <log@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <psim@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <psim@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    12c7 <bw+0x1a7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bw>:
sub    $0x28,%rsp
movsd  0xed4(%rip),%xmm3
mulsd  %xmm0,%xmm3
movapd 0xee8(%rip),%xmm4
xorpd  %xmm2,%xmm4
divsd  %xmm1,%xmm4
movapd %xmm4,0x10(%rsp)
ucomisd %xmm2,%xmm3
jbe    1182 <bw+0x62>
mulsd  0xebc(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1030 <psim@plt>
addsd  0xeb3(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
call   1030 <psim@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
jmp    11cd <bw+0xad>
mulsd  0xe7e(%rip),%xmm2
divsd  %xmm2,%xmm0
call   1040 <log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe67(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1030 <psim@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
call   1030 <psim@plt>
movapd %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
maxsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @bw(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store double 1.200000e-01, double* %8
store double 1.250000e+02, double* %9
%12 = load double, double* %8
%13 = load double, double* %9
%14 = fdiv double %12, %13
%15 = load double, double* %4
%16 = fmul double %14, %15
store double %16, double* %10
%17 = load double, double* %6
%18 = fneg double %17
%19 = load double, double* %5
%20 = fdiv double %18, %19
store double %20, double* %11
%21 = load double, double* %6
%22 = load double, double* %10
%23 = fcmp olt double %21, %22
br i1 %23, label %24, label %42
24: ; preds = %3
%25 = load double, double* %8
%26 = call double @log(double %25)
%27 = fneg double %26
%28 = load double, double* %8
%29 = fneg double %28
%30 = load double, double* %4
%31 = fmul double %29, %30
%32 = load double, double* %5
%33 = fdiv double %31, %32
%34 = call double @psim(double %33)
%35 = fadd double %27, %34
%36 = load double, double* %6
%37 = fneg double %36
%38 = load double, double* %5
%39 = fdiv double %37, %38
%40 = call double @psim(double %39)
%41 = fsub double %35, %40
store double %41, double* %7
br label %60
42: ; preds = %3
%43 = load double, double* %4
%44 = load double, double* %9
%45 = load double, double* %6
%46 = fmul double %44, %45
%47 = fdiv double %43, %46
%48 = call double @log(double %47)
%49 = load double, double* %9
%50 = load double, double* %11
%51 = fmul double %49, %50
%52 = call double @psim(double %51)
%53 = fadd double %48, %52
%54 = load double, double* %6
%55 = fneg double %54
%56 = load double, double* %5
%57 = fdiv double %55, %56
%58 = call double @psim(double %57)
%59 = fadd double %53, %58
store double %59, double* %7
br label %60
60: ; preds = %42, %24
%61 = load double, double* %7
%62 = fcmp olt double %61, 0.000000e+00
br i1 %62, label %63, label %64
63: ; preds = %60
store double 0.000000e+00, double* %7
br label %64
64: ; preds = %63, %60
%65 = load double, double* %7
ret double %65
}

LLVM IR (-O2):
define double @bw(double %0, double %1, double %2) {
%4 = fmul double %0, 0x3F4F75104D551D68
%5 = fneg double %2
%6 = fdiv double %5, %1
%7 = fcmp ogt double %4, %2
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = fmul double %0, -1.200000e-01
%10 = fdiv double %9, %1
%11 = tail call double @psim(double %10)
%12 = fadd double %11, 0x4000F64CBA970BAE
%13 = tail call double @psim(double %6)
%14 = fsub double %12, %13
br label %24
15: ; preds = %3
%16 = fmul double %2, 1.250000e+02
%17 = fdiv double %0, %16
%18 = tail call double @log(double %17)
%19 = fmul double %6, 1.250000e+02
%20 = tail call double @psim(double %19)
%21 = fadd double %18, %20
%22 = tail call double @psim(double %6)
%23 = fadd double %21, %22
br label %24
24: ; preds = %15, %8
%25 = phi double [ %14, %8 ], [ %23, %15 ]
%26 = fcmp olt double %25, 0.000000e+00
%27 = select i1 %26, double 0.000000e+00, double %25
ret double %27
}