#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 bessi0(double);
double sqrt(double);
double getKaiser(double x, double alpha) {
  static double alpha_prev = 0.0;
  static double Ia = 1.0;
  double beta, win;
  if (alpha != alpha_prev) {
    Ia = bessi0(alpha);
    alpha_prev = alpha;
  }
  if (x <= -1.0 || x >= 1.0)
    win = 0.0;
  else {
    beta = alpha * sqrt(1.0 - x * x);
    win = bessi0(beta) / Ia;
  }
  return win;
}


x86 assembly (clang, -O0):
<getKaiser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd 0x2f01(%rip),%xmm0
jne    1150 <getKaiser+0x30>
jp     1150 <getKaiser+0x30>
jmp    116f <getKaiser+0x4f>
movsd  -0x10(%rbp),%xmm0
call   1030 <bessi0@plt>
movsd  %xmm0,0x2ece(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,0x2ed1(%rip)
movsd  0xe89(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jae    1199 <getKaiser+0x79>
movsd  -0x8(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a6 <getKaiser+0x86>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120e <getKaiser+0xee>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe2b(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <bessi0@plt>
divsd  0x2e27(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getKaiser>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
movsd  0x2f10(%rip),%xmm0
ucomisd %xmm1,%xmm0
jne    1138 <getKaiser+0x18>
jnp    1169 <getKaiser+0x49>
movapd %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1030 <bessi0@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,0x2ecf(%rip)
movsd  %xmm1,0x2ed7(%rip)
movsd  0xe8f(%rip),%xmm0
ucomisd %xmm2,%xmm0
xorpd  %xmm0,%xmm0
jae    11c7 <getKaiser+0xa7>
ucomisd 0xe85(%rip),%xmm2
jae    11c7 <getKaiser+0xa7>
mulsd  %xmm2,%xmm2
movsd  0xe77(%rip),%xmm0
subsd  %xmm2,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     11a5 <getKaiser+0x85>
sqrtsd %xmm0,%xmm0
jmp    11b6 <getKaiser+0x96>
movsd  %xmm1,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <bessi0@plt>
divsd  0x2e69(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@getKaiser.alpha_prev = internal global double 0.000000e+00
@getKaiser.Ia = internal global double 1.000000e+00
define double @getKaiser(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %3
store double %1, double* %4
%7 = load double, double* %4
%8 = load double, double* @getKaiser.alpha_prev
%9 = fcmp une double %7, %8
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load double, double* %4
%12 = call double @bessi0(double %11)
store double %12, double* @getKaiser.Ia
%13 = load double, double* %4
store double %13, double* @getKaiser.alpha_prev
br label %14
14: ; preds = %10, %2
%15 = load double, double* %3
%16 = fcmp ole double %15, -1.000000e+00
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load double, double* %3
%19 = fcmp oge double %18, 1.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %17, %14
store double 0.000000e+00, double* %6
br label %33
21: ; preds = %17
%22 = load double, double* %4
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fneg double %23
%26 = call double @llvm.fmuladd.f64(double %25, double %24, double 1.000000e+00)
%27 = call double @sqrt(double %26)
%28 = fmul double %22, %27
store double %28, double* %5
%29 = load double, double* %5
%30 = call double @bessi0(double %29)
%31 = load double, double* @getKaiser.Ia
%32 = fdiv double %30, %31
store double %32, double* %6
br label %33
33: ; preds = %21, %20
%34 = load double, double* %6
ret double %34
}

LLVM IR (-O2):
@getKaiser.alpha_prev = internal unnamed_addr global double 0.000000e+00
@getKaiser.Ia = internal unnamed_addr global double 1.000000e+00
define double @getKaiser(double %0, double %1) {
%3 = load double, double* @getKaiser.alpha_prev
%4 = fcmp une double %3, %1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call double @bessi0(double %1)
store double %6, double* @getKaiser.Ia
store double %1, double* @getKaiser.alpha_prev
br label %7
7: ; preds = %5, %2
%8 = fcmp ole double %0, -1.000000e+00
%9 = fcmp oge double %0, 1.000000e+00
%10 = or i1 %8, %9
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = fneg double %0
%13 = tail call double @llvm.fmuladd.f64(double %12, double %0, double 1.000000e+00)
%14 = tail call double @sqrt(double %13)
%15 = fmul double %14, %1
%16 = tail call double @bessi0(double %15)
%17 = load double, double* @getKaiser.Ia
%18 = fdiv double %16, %17
br label %19
19: ; preds = %7, %11
%20 = phi double [ %18, %11 ], [ 0.000000e+00, %7 ]
ret double %20
}