#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 M_PI;
double cos(double);
void Hanning_r(double *signal, const unsigned int length, double *w) {
  for (unsigned int i = 0; i < length; i++) {
    w[i] = signal[i] * (1.0 - cos(2.0 * M_PI * (i + 1) / length));
  }
}


x86 assembly (clang, -O0):
<Hanning_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11a9 <Hanning_r+0x99>
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
mov    %edx,%eax
movsd  (%rcx,%rdx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2e96(%rip),%rcx
movsd  (%rcx),%xmm0
addsd  %xmm0,%xmm0
add    $0x1,%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <Hanning_r+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Hanning_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
je     1193 <Hanning_r+0x83>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%r13d
cvtsi2sd %r13,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
mov    0x2ea9(%rip),%r12
nop
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%r12),%xmm1
addsd  %xmm1,%xmm1
lea    0x1(%rbx),%rbp
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  %xmm1,%xmm0
divsd  0x8(%rsp),%xmm0
call   1030 <cos@plt>
movsd  0xe85(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  %xmm1,(%r14,%rbx,8)
mov    %rbp,%rbx
cmp    %rbp,%r13
jne    1140 <Hanning_r+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @Hanning_r(double* %0, i32 %1, double* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double* %2, double** %6
store i32 0, i32* %7
br label %8
8: ; preds = %34, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %8
%13 = load double*, double** %4
%14 = load i32, i32* %7
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = load double, double* @M_PI
%19 = fmul double 2.000000e+00, %18
%20 = load i32, i32* %7
%21 = add i32 %20, 1
%22 = uitofp i32 %21 to double
%23 = fmul double %19, %22
%24 = load i32, i32* %5
%25 = uitofp i32 %24 to double
%26 = fdiv double %23, %25
%27 = call double @cos(double %26)
%28 = fsub double 1.000000e+00, %27
%29 = fmul double %17, %28
%30 = load double*, double** %6
%31 = load i32, i32* %7
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %12
%35 = load i32, i32* %7
%36 = add i32 %35, 1
store i32 %36, i32* %7
br label %8
37: ; preds = %8
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @Hanning_r(double* nocapture %0, i32 %1, double* nocapture writeonly %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = uitofp i32 %1 to double
%7 = zext i32 %1 to i64
br label %9
8: ; preds = %9, %3
ret void
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %15, %9 ]
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = load double, double* @M_PI
%14 = fmul double %13, 2.000000e+00
%15 = add nuw nsw i64 %10, 1
%16 = trunc i64 %15 to i32
%17 = uitofp i32 %16 to double
%18 = fmul double %14, %17
%19 = fdiv double %18, %6
%20 = tail call double @cos(double %19)
%21 = fsub double 1.000000e+00, %20
%22 = fmul double %12, %21
%23 = getelementptr inbounds double, double* %2, i64 %10
store double %22, double* %23
%24 = icmp eq i64 %15, %7
br i1 %24, label %8, label %9
}