#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 const cos(double);
double const fabs(int);
void bartlett_hann(double *window, const int N) {
  int n;
  const double M = N - 1, a0 = 0.62, a1 = 0.5, a2 = 0.38;
  double term1 = 0.0, term2 = 0.0;
  for (n = 0; n < N; n++) {
    term1 = a1 * fabs(n / M - 0.5);
    term2 = a2 * cos(2.0 * 3.14159265358979323846264338327 * (double)n / M);
    window[n] = a0 - term1 - term2;
  }
}


x86 assembly (clang, -O0):
<bartlett_hann>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeca(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeb5(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xea0(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1217 <bartlett_hann+0xf7>
cvtsi2sdl -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xe56(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xe50(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  0xe1f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe1e(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117c <bartlett_hann+0x5c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bartlett_hann>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %esi,%esi
jle    11c8 <bartlett_hann+0xa8>
mov    %rdi,%r14
lea    -0x1(%rsi),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %esi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x18(%rsp)
divsd  0x8(%rsp),%xmm0
movsd  0xe95(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <fabs@plt>
mulsd  0xe80(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xe74(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0xe69(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  0xe63(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <bartlett_hann+0x30>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bartlett_hann(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = sitofp i32 %13 to double
store double %14, double* %6
store double 6.200000e-01, double* %7
store double 5.000000e-01, double* %8
store double 3.800000e-01, double* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %5
br label %15
15: ; preds = %43, %2
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %46
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sitofp i32 %20 to double
%22 = load double, double* %6
%23 = fdiv double %21, %22
%24 = fsub double %23, 5.000000e-01
%25 = fptosi double %24 to i32
%26 = call double @fabs(i32 %25)
%27 = fmul double 5.000000e-01, %26
store double %27, double* %10
%28 = load i32, i32* %5
%29 = sitofp i32 %28 to double
%30 = fmul double 0x401921FB54442D18, %29
%31 = load double, double* %6
%32 = fdiv double %30, %31
%33 = call double @cos(double %32)
%34 = fmul double 3.800000e-01, %33
store double %34, double* %11
%35 = load double, double* %10
%36 = fsub double 6.200000e-01, %35
%37 = load double, double* %11
%38 = fsub double %36, %37
%39 = load double*, double** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
store double %38, double* %42
br label %43
43: ; preds = %19
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %15
46: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @bartlett_hann(double* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sitofp i32 %3 to double
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %26
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %24, %8 ]
%10 = trunc i64 %9 to i32
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, %4
%13 = fadd double %12, -5.000000e-01
%14 = fptosi double %13 to i32
%15 = tail call double @fabs(i32 %14)
%16 = fmul double %15, 5.000000e-01
%17 = fmul double %11, 0x401921FB54442D18
%18 = fdiv double %17, %4
%19 = tail call double @cos(double %18)
%20 = fmul double %19, 3.800000e-01
%21 = fsub double 6.200000e-01, %16
%22 = fsub double %21, %20
%23 = getelementptr inbounds double, double* %0, i64 %9
store double %22, double* %23
%24 = add nuw nsw i64 %9, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %8
26: ; preds = %8, %2
ret void
}