#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 sqrt(double);
float lkdrag(float Tsurf, double Tair, double wind, double roughness,
             double Z1) {
  double cdrn, ribn, ribd, rib;
  double cdr, cdrmin;
  cdrn = (0.40 / log(Z1 / roughness)) * (0.40 / log(Z1 / roughness));
  ribn = Z1 * 9.81 * (1. - Tsurf / Tair);
  if ((Tsurf / Tair) <= 1.0) {
    ribd = wind * wind + 0.1 * 0.1;
  } else {
    ribd = wind * wind + 1.0 * 1.0;
  }
  rib = ribn / ribd;
  if (rib < 0.) {
    cdr = cdrn * (1.0 + 24.5 * sqrt(-cdrn * rib));
  } else {
    cdr = cdrn / (1.0 + 11.5 * rib);
  }
  if ((.25 * cdrn) > 6.e-4)
    cdrmin = .25 * cdrn;
  else
    cdrmin = 6.e-4;
  if (cdr < cdrmin)
    cdr = cdrmin;
  return (cdr);
}


x86 assembly (clang, -O0):
<lkdrag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movss  %xmm0,-0x4(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xeb5(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movsd  0xe8d(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe70(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
divsd  -0x10(%rbp),%xmm2
movsd  0xe4d(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
divsd  -0x10(%rbp),%xmm1
movsd  0xe2a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1204 <lkdrag+0xe4>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe22(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1223 <lkdrag+0x103>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xde6(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    129e <lkdrag+0x17e>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x48(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
movsd  0xda8(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd74(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    12c9 <lkdrag+0x1a9>
movsd  -0x30(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  0xd70(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd44(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xd67(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  0xd52(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12ff <lkdrag+0x1df>
movsd  0xd48(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    130c <lkdrag+0x1ec>
movsd  0xd29(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    132a <lkdrag+0x20a>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lkdrag>:
sub    $0x48,%rsp
movsd  %xmm4,0x38(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x40(%rsp)
movss  %xmm0,0xc(%rsp)
movapd %xmm4,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
call   1030 <log@plt>
movsd  0xea9(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
movsd  0x28(%rsp),%xmm0
call   1030 <log@plt>
movsd  0xe8c(%rip),%xmm3
divsd  %xmm0,%xmm3
movsd  0x38(%rsp),%xmm2
mulsd  0xe82(%rip),%xmm2
movss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
divsd  0x40(%rsp),%xmm1
movsd  0xe6f(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mulsd  0x30(%rsp),%xmm3
setb   %al
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
lea    0xe77(%rip),%rcx
addsd  (%rcx,%rax,8),%xmm1
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11fb <lkdrag+0xdb>
movapd 0xe6c(%rip),%xmm2
xorpd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1215 <lkdrag+0xf5>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    122a <lkdrag+0x10a>
mulsd  0xe15(%rip),%xmm0
addsd  0xe05(%rip),%xmm0
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
jmp    123e <lkdrag+0x11e>
movapd %xmm3,0x10(%rsp)
call   1040 <sqrt@plt>
movapd 0x10(%rsp),%xmm3
movapd %xmm0,%xmm1
mulsd  0xdee(%rip),%xmm1
addsd  0xdd6(%rip),%xmm1
mulsd  %xmm3,%xmm1
mulsd  0xde2(%rip),%xmm3
maxsd  0xde2(%rip),%xmm3
maxsd  %xmm1,%xmm3
xorps  %xmm0,%xmm0
cvtsd2ss %xmm3,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define float @lkdrag(float %0, double %1, double %2, double %3, double %4) {
%6 = alloca float
%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 float %0, float* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
%17 = load double, double* %10
%18 = load double, double* %9
%19 = fdiv double %17, %18
%20 = call double @log(double %19)
%21 = fdiv double 4.000000e-01, %20
%22 = load double, double* %10
%23 = load double, double* %9
%24 = fdiv double %22, %23
%25 = call double @log(double %24)
%26 = fdiv double 4.000000e-01, %25
%27 = fmul double %21, %26
store double %27, double* %11
%28 = load double, double* %10
%29 = fmul double %28, 9.810000e+00
%30 = load float, float* %6
%31 = fpext float %30 to double
%32 = load double, double* %7
%33 = fdiv double %31, %32
%34 = fsub double 1.000000e+00, %33
%35 = fmul double %29, %34
store double %35, double* %12
%36 = load float, float* %6
%37 = fpext float %36 to double
%38 = load double, double* %7
%39 = fdiv double %37, %38
%40 = fcmp ole double %39, 1.000000e+00
br i1 %40, label %41, label %45
41: ; preds = %5
%42 = load double, double* %8
%43 = load double, double* %8
%44 = call double @llvm.fmuladd.f64(double %42, double %43, double 0x3F847AE147AE147C)
store double %44, double* %13
br label %49
45: ; preds = %5
%46 = load double, double* %8
%47 = load double, double* %8
%48 = call double @llvm.fmuladd.f64(double %46, double %47, double 1.000000e+00)
store double %48, double* %13
br label %49
49: ; preds = %45, %41
%50 = load double, double* %12
%51 = load double, double* %13
%52 = fdiv double %50, %51
store double %52, double* %14
%53 = load double, double* %14
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %64
55: ; preds = %49
%56 = load double, double* %11
%57 = load double, double* %11
%58 = fneg double %57
%59 = load double, double* %14
%60 = fmul double %58, %59
%61 = call double @sqrt(double %60)
%62 = call double @llvm.fmuladd.f64(double 2.450000e+01, double %61, double 1.000000e+00)
%63 = fmul double %56, %62
store double %63, double* %15
br label %69
64: ; preds = %49
%65 = load double, double* %11
%66 = load double, double* %14
%67 = call double @llvm.fmuladd.f64(double 1.150000e+01, double %66, double 1.000000e+00)
%68 = fdiv double %65, %67
store double %68, double* %15
br label %69
69: ; preds = %64, %55
%70 = load double, double* %11
%71 = fmul double 2.500000e-01, %70
%72 = fcmp ogt double %71, 6.000000e-04
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = load double, double* %11
%75 = fmul double 2.500000e-01, %74
store double %75, double* %16
br label %77
76: ; preds = %69
store double 6.000000e-04, double* %16
br label %77
77: ; preds = %76, %73
%78 = load double, double* %15
%79 = load double, double* %16
%80 = fcmp olt double %78, %79
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = load double, double* %16
store double %82, double* %15
br label %83
83: ; preds = %81, %77
%84 = load double, double* %15
%85 = fptrunc double %84 to float
ret float %85
}

LLVM IR (-O2):
define float @lkdrag(float %0, double %1, double %2, double %3, double %4) {
%6 = fdiv double %4, %3
%7 = tail call double @log(double %6)
%8 = fdiv double 4.000000e-01, %7
%9 = tail call double @log(double %6)
%10 = fdiv double 4.000000e-01, %9
%11 = fmul double %8, %10
%12 = fmul double %4, 9.810000e+00
%13 = fpext float %0 to double
%14 = fdiv double %13, %1
%15 = fsub double 1.000000e+00, %14
%16 = fmul double %15, %12
%17 = fcmp ugt double %14, 1.000000e+00
%18 = tail call double @llvm.fmuladd.f64(double %2, double %2, double 0x3F847AE147AE147C)
%19 = tail call double @llvm.fmuladd.f64(double %2, double %2, double 1.000000e+00)
%20 = select i1 %17, double %19, double %18
%21 = fdiv double %16, %20
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %29
23: ; preds = %5
%24 = fneg double %11
%25 = fmul double %21, %24
%26 = tail call double @sqrt(double %25)
%27 = tail call double @llvm.fmuladd.f64(double %26, double 2.450000e+01, double 1.000000e+00)
%28 = fmul double %11, %27
br label %32
29: ; preds = %5
%30 = tail call double @llvm.fmuladd.f64(double %21, double 1.150000e+01, double 1.000000e+00)
%31 = fdiv double %11, %30
br label %32
32: ; preds = %29, %23
%33 = phi double [ %28, %23 ], [ %31, %29 ]
%34 = fmul double %11, 2.500000e-01
%35 = fcmp ogt double %34, 6.000000e-04
%36 = select i1 %35, double %34, double 6.000000e-04
%37 = fcmp olt double %33, %36
%38 = select i1 %37, double %36, double %33
%39 = fptrunc double %38 to float
ret float %39
}