#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 */
int M_PI;
double const cos(double);
void calc_nuttall_window(double *data, int datalen) {
  const double a[4] = {0.355768, 0.487396, 0.144232, 0.012604};
  int k;
  for (k = 0; k < datalen; k++) {
    double scale;
    scale = M_PI * k / (datalen - 1);
    data[k] = a[0] - a[1] * cos(2.0 * scale) + a[2] * cos(4.0 * scale) -
              a[3] * cos(6.0 * scale);
  };
  return;
}


x86 assembly (clang, -O0):
<calc_nuttall_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xefa(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xef7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xef4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xef1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126d <calc_nuttall_window+0x15d>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
imul   -0x34(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xe77(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe22(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xde4(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1152 <calc_nuttall_window+0x42>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_nuttall_window>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11cd <calc_nuttall_window+0xbd>
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%r15d
add    $0xffffffff,%ebp
xor    %ebx,%ebx
mov    0x2eb0(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r12),%eax
imul   %ebx,%eax
cltd
idiv   %ebp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
addsd  %xmm0,%xmm0
call   1030 <cos@plt>
mulsd  0xe98(%rip),%xmm0
addsd  0xe98(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe8d(%rip),%xmm0
call   1030 <cos@plt>
mulsd  0xe88(%rip),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe78(%rip),%xmm0
call   1030 <cos@plt>
mulsd  0xe73(%rip),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <calc_nuttall_window+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.calc_nuttall_window.a = [4 x double] [double 3.557680e-01, double 4.873960e-01, double 1.442320e-01, double 1.260400e-02]
@M_PI = global i32 0
define void @calc_nuttall_window(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca [4 x double]
%6 = alloca i32
%7 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%8 = bitcast [4 x double]* %5 to i8*
store i32 0, i32* %6
br label %9
9: ; preds = %47, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %50
13: ; preds = %9
%14 = load i32, i32* @M_PI
%15 = load i32, i32* %6
%16 = mul nsw i32 %14, %15
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = sdiv i32 %16, %18
%20 = sitofp i32 %19 to double
store double %20, double* %7
%21 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%22 = load double, double* %21
%23 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
%24 = load double, double* %23
%25 = load double, double* %7
%26 = fmul double 2.000000e+00, %25
%27 = call double @cos(double %26)
%28 = fneg double %24
%29 = call double @llvm.fmuladd.f64(double %28, double %27, double %22)
%30 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
%31 = load double, double* %30
%32 = load double, double* %7
%33 = fmul double 4.000000e+00, %32
%34 = call double @cos(double %33)
%35 = call double @llvm.fmuladd.f64(double %31, double %34, double %29)
%36 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
%37 = load double, double* %36
%38 = load double, double* %7
%39 = fmul double 6.000000e+00, %38
%40 = call double @cos(double %39)
%41 = fneg double %37
%42 = call double @llvm.fmuladd.f64(double %41, double %40, double %35)
%43 = load double*, double** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
store double %42, double* %46
br label %47
47: ; preds = %13
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %9
50: ; preds = %9
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @calc_nuttall_window(double* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %4, %7
%8 = phi i64 [ 0, %4 ], [ %24, %7 ]
%9 = load i32, i32* @M_PI
%10 = trunc i64 %8 to i32
%11 = mul nsw i32 %9, %10
%12 = sdiv i32 %11, %5
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 2.000000e+00
%15 = tail call double @cos(double %14)
%16 = tail call double @llvm.fmuladd.f64(double %15, double -4.873960e-01, double 3.557680e-01)
%17 = fmul double %13, 4.000000e+00
%18 = tail call double @cos(double %17)
%19 = tail call double @llvm.fmuladd.f64(double %18, double 1.442320e-01, double %16)
%20 = fmul double %13, 6.000000e+00
%21 = tail call double @cos(double %20)
%22 = tail call double @llvm.fmuladd.f64(double %21, double -1.260400e-02, double %19)
%23 = getelementptr inbounds double, double* %0, i64 %8
store double %22, double* %23
%24 = add nuw nsw i64 %8, 1
%25 = icmp eq i64 %24, %6
br i1 %25, label %26, label %7
26: ; preds = %7, %2
ret void
}