#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 besseli0(double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ isfinite(double);
int /*<<< orphan*/ printf(char *, double, double);
double sqrt(double);
void calc_kaiser_window(double *data, int datalen, double beta) {
  double two_n_on_N, denom;
  int k;
  denom = besseli0(beta);
  if (!isfinite(denom)) {
    printf("besseli0 (%f) : %f\nExiting\n", beta, denom);
    exit(1);
  };
  for (k = 0; k < datalen; k++) {
    double n = k + 0.5 - 0.5 * datalen;
    two_n_on_N = (2.0 * n) / datalen;
    data[k] = besseli0(beta * sqrt(1.0 - two_n_on_N * two_n_on_N)) / denom;
  };
  return;
}


x86 assembly (clang, -O0):
<calc_kaiser_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <besseli0@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%eax
jne    11a6 <calc_kaiser_window+0x56>
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1270 <calc_kaiser_window+0x120>
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe52(%rip),%xmm0
addsd  %xmm0,%xmm1
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe39(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe1c(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdca(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <besseli0@plt>
divsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ad <calc_kaiser_window+0x5d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_kaiser_window>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
movsd  %xmm0,0x8(%rsp)
call   1050 <besseli0@plt>
movsd  %xmm0,(%rsp)
call   1040 <isfinite@plt>
test   %eax,%eax
je     121c <calc_kaiser_window+0xcc>
test   %ebp,%ebp
jle    1213 <calc_kaiser_window+0xc3>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mov    %ebp,%ebp
xor    %ebx,%ebx
movsd  0xe73(%rip),%xmm1
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
jmp    11d4 <calc_kaiser_window+0x84>
nopw   0x0(%rax,%rax,1)
call   1060 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
call   1050 <besseli0@plt>
divsd  (%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1213 <calc_kaiser_window+0xc3>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
addsd  0xe1d(%rip),%xmm1
addsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
divsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm1
movsd  0xe11(%rip),%xmm0
subsd  %xmm1,%xmm0
ucomisd 0xe0d(%rip),%xmm0
jb     11b0 <calc_kaiser_window+0x60>
sqrtsd %xmm0,%xmm0
jmp    11b5 <calc_kaiser_window+0x65>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdfd(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"besseli0 (%f) : %f\0AExiting\0A\00"
define void @calc_kaiser_window(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%11 = load double, double* %6
%12 = call double @besseli0(double %11)
store double %12, double* %8
%13 = load double, double* %8
%14 = call i32 @isfinite(double %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %3
%17 = load double, double* %6
%18 = load double, double* %8
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %17, double %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
store i32 0, i32* %9
br label %22
22: ; preds = %52, %21
%23 = load i32, i32* %9
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %55
26: ; preds = %22
%27 = load i32, i32* %9
%28 = sitofp i32 %27 to double
%29 = fadd double %28, 5.000000e-01
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to double
%32 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %31, double %29)
store double %32, double* %10
%33 = load double, double* %10
%34 = fmul double 2.000000e+00, %33
%35 = load i32, i32* %5
%36 = sitofp i32 %35 to double
%37 = fdiv double %34, %36
store double %37, double* %7
%38 = load double, double* %6
%39 = load double, double* %7
%40 = load double, double* %7
%41 = fneg double %39
%42 = call double @llvm.fmuladd.f64(double %41, double %40, double 1.000000e+00)
%43 = call double @sqrt(double %42)
%44 = fmul double %38, %43
%45 = call double @besseli0(double %44)
%46 = load double, double* %8
%47 = fdiv double %45, %46
%48 = load double*, double** %4
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
store double %47, double* %51
br label %52
52: ; preds = %26
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %22
55: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"besseli0 (%f) : %f\0AExiting\0A\00"
define void @calc_kaiser_window(double* nocapture writeonly %0, i32 %1, double %2) {
%4 = tail call double @besseli0(double %2)
%5 = tail call i32 @isfinite(double %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %32
9: ; preds = %7
%10 = sitofp i32 %1 to double
%11 = zext i32 %1 to i64
br label %15
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), double %2, double %4)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %15
%16 = phi i64 [ 0, %9 ], [ %30, %15 ]
%17 = trunc i64 %16 to i32
%18 = sitofp i32 %17 to double
%19 = fadd double %18, 5.000000e-01
%20 = tail call double @llvm.fmuladd.f64(double %10, double -5.000000e-01, double %19)
%21 = fmul double %20, 2.000000e+00
%22 = fdiv double %21, %10
%23 = fneg double %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double %22, double 1.000000e+00)
%25 = tail call double @sqrt(double %24)
%26 = fmul double %25, %2
%27 = tail call double @besseli0(double %26)
%28 = fdiv double %27, %4
%29 = getelementptr inbounds double, double* %0, i64 %16
store double %28, double* %29
%30 = add nuw nsw i64 %16, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %32, label %15
32: ; preds = %15, %7
ret void
}