double kOZ(double AltS, double sunra, double Lat) {
  double CHANGEKO, OZ, LT, kOZret;
  static __thread double koz_last, alts_last, sunra_last;
  double altslim = 0;
  if (AltS == alts_last && sunra == sunra_last)
    return koz_last;
  alts_last = AltS;
  sunra_last = sunra;
  OZ = 0.031;
  LT = Lat * (3.14159265358979323846 / 180.0);
  kOZret = OZ *
           (3.0 + 0.4 * (LT * cos(sunra * (3.14159265358979323846 / 180.0)) -
                         cos(3 * LT))) /
           3.0;
  altslim = -AltS - 12;
  if (altslim < 0)
    altslim = 0;
  CHANGEKO = (100 - 11.6 * mymin(6, altslim)) / 100;
  if ((0)) {
    static int a = 0;
    if (a == 0)
      printf("bsk=%f %f\n", kOZret, AltS);
    a = 1;
  }
  koz_last = kOZret * CHANGEKO;
  return koz_last;
}


x86 assembly (clang, -O0):
<kOZ>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movq   $0x0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
lea    0x2e6d(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  -0x50(%rbp),%xmm0
movsd  0x8(%rax),%xmm1
ucomisd %xmm1,%xmm0
jne    11d6 <kOZ+0xa6>
jp     11d6 <kOZ+0xa6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
lea    0x2e3a(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  -0x58(%rbp),%xmm0
movsd  0x10(%rax),%xmm1
ucomisd %xmm1,%xmm0
jne    11d6 <kOZ+0xa6>
jp     11d6 <kOZ+0xa6>
lea    0x2e11(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  0x0(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138e <kOZ+0x25e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
lea    0x2de9(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
lea    0x2dc6(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,0x10(%rax)
movsd  0xdfc(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xde7(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xdc1(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  0xd9a(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x70(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm3
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xd5f(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd4b(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd3b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd06(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1319 <kOZ+0x1e9>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    $0x6,%edi
mov    $0x1,%al
call   1050 <mymin@plt>
cvtsi2sd %eax,%xmm0
movsd  0xcf2(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcee(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
lea    0x2c64(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,0x0(%rax)
movsd  0x0(%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kOZ>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x28(%rsp)
lea    0x2e82(%rip),%rdi
call   1030 <__tls_get_addr@plt>
movsd  0x10(%rsp),%xmm0
mov    %rax,%rbx
movsd  0x8(%rax),%xmm2
movsd  0x28(%rsp),%xmm3
movapd %xmm3,%xmm1
ucomisd %xmm3,%xmm2
jne    1196 <kOZ+0x66>
jp     1196 <kOZ+0x66>
movsd  0x10(%rax),%xmm2
ucomisd %xmm0,%xmm2
jne    1196 <kOZ+0x66>
jp     1196 <kOZ+0x66>
mov    %rbx,%rax
movsd  0x0(%rbx),%xmm0
jmp    1270 <kOZ+0x140>
movsd  %xmm1,0x8(%rbx)
movsd  %xmm0,0x10(%rbx)
movsd  0xe52(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm1,%xmm0
call   1040 <cos@plt>
movapd %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe2d(%rip),%xmm0
call   1040 <cos@plt>
movapd 0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe18(%rip),%xmm1
addsd  0xe08(%rip),%xmm1
mulsd  0xe10(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
movsd  0xe0a(%rip),%xmm1
subsd  0x28(%rsp),%xmm1
xorpd  %xmm0,%xmm0
maxsd  %xmm1,%xmm0
mov    $0x6,%edi
mov    $0x1,%al
call   1050 <mymin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xde9(%rip),%xmm0
addsd  0xde9(%rip),%xmm0
movapd 0x10(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
divpd  0xde7(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mov    %rbx,%rax
movsd  %xmm0,0x0(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@kOZ.koz_last = internal thread_local global double 0.000000e+00
@kOZ.alts_last = internal thread_local global double 0.000000e+00
@kOZ.sunra_last = internal thread_local global double 0.000000e+00
define double @kOZ(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
%12 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double 0.000000e+00, double* %12
%13 = load double, double* %5
%14 = load double, double* @kOZ.alts_last
%15 = fcmp oeq double %13, %14
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load double, double* %6
%18 = load double, double* @kOZ.sunra_last
%19 = fcmp oeq double %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load double, double* @kOZ.koz_last
store double %21, double* %4
br label %56
22: ; preds = %16, %3
%23 = load double, double* %5
store double %23, double* @kOZ.alts_last
%24 = load double, double* %6
store double %24, double* @kOZ.sunra_last
store double 3.100000e-02, double* %9
%25 = load double, double* %7
%26 = fmul double %25, 0x3F91DF46A2529D39
store double %26, double* %10
%27 = load double, double* %9
%28 = load double, double* %10
%29 = load double, double* %6
%30 = fmul double %29, 0x3F91DF46A2529D39
%31 = call double @cos(double %30)
%32 = load double, double* %10
%33 = fmul double 3.000000e+00, %32
%34 = call double @cos(double %33)
%35 = fneg double %34
%36 = call double @llvm.fmuladd.f64(double %28, double %31, double %35)
%37 = call double @llvm.fmuladd.f64(double 4.000000e-01, double %36, double 3.000000e+00)
%38 = fmul double %27, %37
%39 = fdiv double %38, 3.000000e+00
store double %39, double* %11
%40 = load double, double* %5
%41 = fneg double %40
%42 = fsub double %41, 1.200000e+01
store double %42, double* %12
%43 = load double, double* %12
%44 = fcmp olt double %43, 0.000000e+00
br i1 %44, label %45, label %46
45: ; preds = %22
store double 0.000000e+00, double* %12
br label %46
46: ; preds = %45, %22
%47 = load double, double* %12
%48 = call i32 (i32, double, ...) bitcast (i32 (...)* @mymin to i32 (i32, double, ...)*)(i32 6, double %47)
%49 = sitofp i32 %48 to double
%50 = call double @llvm.fmuladd.f64(double -1.160000e+01, double %49, double 1.000000e+02)
%51 = fdiv double %50, 1.000000e+02
store double %51, double* %8
%52 = load double, double* %11
%53 = load double, double* %8
%54 = fmul double %52, %53
store double %54, double* @kOZ.koz_last
%55 = load double, double* @kOZ.koz_last
store double %55, double* %4
br label %56
56: ; preds = %46, %20
%57 = load double, double* %4
ret double %57
}

LLVM IR (-O2):
@kOZ.koz_last = internal thread_local unnamed_addr global double 0.000000e+00
@kOZ.alts_last = internal thread_local unnamed_addr global double 0.000000e+00
@kOZ.sunra_last = internal thread_local unnamed_addr global double 0.000000e+00
define double @kOZ(double %0, double %1, double %2) {
%4 = load double, double* @kOZ.alts_last
%5 = fcmp oeq double %4, %0
%6 = load double, double* @kOZ.sunra_last
%7 = fcmp oeq double %6, %1
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = load double, double* @kOZ.koz_last
br label %33
11: ; preds = %3
store double %0, double* @kOZ.alts_last
store double %1, double* @kOZ.sunra_last
%12 = fmul double %2, 0x3F91DF46A2529D39
%13 = fmul double %1, 0x3F91DF46A2529D39
%14 = tail call double @cos(double %13)
%15 = fmul double %12, 3.000000e+00
%16 = tail call double @cos(double %15)
%17 = fneg double %16
%18 = tail call double @llvm.fmuladd.f64(double %12, double %14, double %17)
%19 = tail call double @llvm.fmuladd.f64(double %18, double 4.000000e-01, double 3.000000e+00)
%20 = fmul double %19, 3.100000e-02
%21 = fsub double -1.200000e+01, %0
%22 = fcmp olt double %21, 0.000000e+00
%23 = select i1 %22, double 0.000000e+00, double %21
%24 = tail call i32 (i32, double, ...) bitcast (i32 (...)* @mymin to i32 (i32, double, ...)*)(i32 6, double %23)
%25 = sitofp i32 %24 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double -1.160000e+01, double 1.000000e+02)
%27 = insertelement <2 x double> poison, double %20, i64 0
%28 = insertelement <2 x double> %27, double %26, i64 1
%29 = fdiv <2 x double> %28, <double 3.000000e+00, double 1.000000e+02>
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%31 = fmul <2 x double> %29, %30
%32 = extractelement <2 x double> %31, i64 0
store double %32, double* @kOZ.koz_last
br label %33
33: ; preds = %11, %9
%34 = phi double [ %10, %9 ], [ %32, %11 ]
ret double %34
}