#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(double);
void hann(double *array, int length) {
  int i;
  if (length == 1)
    *array = 1.0;
  else
    for (i = 0; i < length; i++)
      array[i] = 0.5 * (1 - cos(2.0 * 3.14159265358979323846 * (double)i /
                                (double)(length - 1)));
}


x86 assembly (clang, -O0):
<hann>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    113e <hann+0x2e>
mov    -0x8(%rbp),%rax
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    11ae <hann+0x9e>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <hann+0x99>
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xeaa(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe76(%rip),%xmm0
mulsd  %xmm1,%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    1145 <hann+0x35>
jmp    11ae <hann+0x9e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hann>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x1,%esi
jne    1132 <hann+0x22>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%r14)
jmp    1232 <hann+0x122>
jl     1232 <hann+0x122>
lea    -0x1(%rsi),%eax
cvtsi2sd %eax,%xmm0
mov    %esi,%r15d
cmp    $0x1,%esi
jne    1158 <hann+0x48>
xor    %ebx,%ebx
test   $0x1,%r15b
jne    11fa <hann+0xea>
jmp    1232 <hann+0x122>
mov    %r15d,%r12d
and    $0xfffffffe,%r12d
xor    %ebx,%ebx
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe81(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  (%rsp),%xmm0
call   1030 <cos@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xe65(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe41(%rip),%xmm0
divsd  (%rsp),%xmm0
call   1030 <cos@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0xe29(%rip),%xmm0
movsd  %xmm0,0x8(%r14,%rbx,8)
add    $0x2,%rbx
cmp    %r12,%rbx
jne    1170 <hann+0x60>
movsd  (%rsp),%xmm0
test   $0x1,%r15b
je     1232 <hann+0x122>
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xdf3(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0xddc(%rip),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @hann(double* nocapture writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %53
6: ; preds = %4
%7 = add nsw i32 %1, -1
%8 = sitofp i32 %7 to double
%9 = zext i32 %1 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %1, 1
br i1 %11, label %40, label %12
12: ; preds = %6
%13 = and i64 %9, 4294967294
br label %15
14: ; preds = %2
store double 1.000000e+00, double* %0
br label %53
15: ; preds = %15, %12
%16 = phi i64 [ 0, %12 ], [ %37, %15 ]
%17 = phi i64 [ 0, %12 ], [ %38, %15 ]
%18 = trunc i64 %16 to i32
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 0x401921FB54442D18
%21 = fdiv double %20, %8
%22 = tail call i32 @cos(double %21)
%23 = sub nsw i32 1, %22
%24 = sitofp i32 %23 to double
%25 = fmul double %24, 5.000000e-01
%26 = getelementptr inbounds double, double* %0, i64 %16
store double %25, double* %26
%27 = or i64 %16, 1
%28 = trunc i64 %27 to i32
%29 = sitofp i32 %28 to double
%30 = fmul double %29, 0x401921FB54442D18
%31 = fdiv double %30, %8
%32 = tail call i32 @cos(double %31)
%33 = sub nsw i32 1, %32
%34 = sitofp i32 %33 to double
%35 = fmul double %34, 5.000000e-01
%36 = getelementptr inbounds double, double* %0, i64 %27
store double %35, double* %36
%37 = add nuw nsw i64 %16, 2
%38 = add i64 %17, 2
%39 = icmp eq i64 %38, %13
br i1 %39, label %40, label %15
40: ; preds = %15, %6
%41 = phi i64 [ 0, %6 ], [ %37, %15 ]
%42 = icmp eq i64 %10, 0
br i1 %42, label %53, label %43
43: ; preds = %40
%44 = trunc i64 %41 to i32
%45 = sitofp i32 %44 to double
%46 = fmul double %45, 0x401921FB54442D18
%47 = fdiv double %46, %8
%48 = tail call i32 @cos(double %47)
%49 = sub nsw i32 1, %48
%50 = sitofp i32 %49 to double
%51 = fmul double %50, 5.000000e-01
%52 = getelementptr inbounds double, double* %0, i64 %41
store double %51, double* %52
br label %53
53: ; preds = %43, %40, %4, %14
ret void
}