#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 cos(int);
void hann(float *hann, int N) {
  float M;
  int n;
  M = (N - 1) / 2;
  for (n = 0; n < N; n++) {
    hann[n] = 0.5 * (1 + cos(2 * 3.14159265359 * ((float)n - M) / (2 * M + 1)));
  }
}


x86 assembly (clang, -O0):
<hann>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bb <hann+0xab>
cvtsi2ssl -0x14(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xea9(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
addss  %xmm1,%xmm1
movss  0xe9c(%rip),%xmm2
addss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe68(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <hann+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hann>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11ad <hann+0x9d>
mov    %rdi,%r14
lea    -0x1(%rsi),%eax
shr    $0x1f,%eax
add    %esi,%eax
add    $0xffffffff,%eax
sar    %eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
addss  %xmm0,%xmm0
addss  0xeb9(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %esi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
subss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe8f(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe76(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <hann+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @hann(float* %0, i32 %1) {
%3 = alloca float*
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
store float* %0, float** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
%9 = sdiv i32 %8, 2
%10 = sitofp i32 %9 to float
store float %10, float* %5
store i32 0, i32* %6
br label %11
11: ; preds = %36, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %39
15: ; preds = %11
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to float
%18 = load float, float* %5
%19 = fsub float %17, %18
%20 = fpext float %19 to double
%21 = fmul double 0x401921FB54442EEA, %20
%22 = load float, float* %5
%23 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %22, float 1.000000e+00)
%24 = fpext float %23 to double
%25 = fdiv double %21, %24
%26 = fptosi double %25 to i32
%27 = call i32 @cos(i32 %26)
%28 = add nsw i32 1, %27
%29 = sitofp i32 %28 to double
%30 = fmul double 5.000000e-01, %29
%31 = fptrunc double %30 to float
%32 = load float*, float** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds float, float* %32, i64 %34
store float %31, float* %35
br label %36
36: ; preds = %15
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %11
39: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @hann(float* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sdiv i32 %3, 2
%5 = sitofp i32 %4 to float
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = tail call float @llvm.fmuladd.f32(float %5, float 2.000000e+00, float 1.000000e+00)
%9 = fpext float %8 to double
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %26, %11 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to float
%15 = fsub float %14, %5
%16 = fpext float %15 to double
%17 = fmul double %16, 0x401921FB54442EEA
%18 = fdiv double %17, %9
%19 = fptosi double %18 to i32
%20 = tail call i32 @cos(i32 %19)
%21 = add nsw i32 %20, 1
%22 = sitofp i32 %21 to double
%23 = fmul double %22, 5.000000e-01
%24 = fptrunc double %23 to float
%25 = getelementptr inbounds float, float* %0, i64 %12
store float %24, float* %25
%26 = add nuw nsw i64 %12, 1
%27 = icmp eq i64 %26, %10
br i1 %27, label %28, label %11
28: ; preds = %11, %2
ret void
}