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


x86 assembly (clang, -O0):
<cw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xec4(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeaf(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1242 <cw+0x122>
movsd  -0x30(%rbp),%xmm0
call   1030 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <psih@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <psih@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b6 <cw+0x196>
movsd  -0x8(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
call   1040 <psih@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x10(%rbp),%xmm0
call   1040 <psih@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12cc <cw+0x1ac>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw>:
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 <cw+0x62>
mulsd  0xebc(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <psih@plt>
addsd  0xeb3(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
call   1040 <psih@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
jmp    11cd <cw+0xad>
mulsd  0xe7e(%rip),%xmm2
divsd  %xmm2,%xmm0
call   1030 <log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe67(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1040 <psih@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
call   1040 <psih@plt>
movapd %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
xorpd  %xmm0,%xmm0
maxsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

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

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