#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);
double *hanning(double *w, const int leng) {
  int i;
  double arg;
  double *p;
  arg = 6.2831853071795864769252867665590 / (leng - 1);
  for (p = w, i = 0; i < leng; i++)
    *p++ = 0.5 * (1 - cos(i * arg));
  return (w);
}


x86 assembly (clang, -O0):
<hanning>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xecf(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <hanning+0x92>
cvtsi2sdl -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe8b(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <hanning+0x39>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hanning>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
test   %esi,%esi
jle    1234 <hanning+0x124>
mov    %esi,%r15d
lea    -0x1(%r15),%eax
cvtsi2sd %eax,%xmm0
movsd  0xec6(%rip),%xmm1
divsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
mov    %r14,%r12
cmp    $0x1,%esi
je     1205 <hanning+0xf5>
mov    %r15d,%ebp
and    $0xfffffffe,%ebp
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
mov    %r14,%r12
movsd  %xmm1,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm2,0x8(%rsp)
movapd %xmm1,%xmm0
mulsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xe6b(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0x1(%rbx),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm0,(%r12)
mulsd  (%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1030 <cos@plt>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0xe28(%rip),%xmm0
movsd  %xmm0,0x8(%r12)
add    $0x10,%r12
addsd  0xe1d(%rip),%xmm2
add    $0x2,%ebx
cmp    %ebx,%ebp
jne    1170 <hanning+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
test   $0x1,%r15b
je     1234 <hanning+0x124>
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <cos@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0xdda(%rip),%xmm0
movsd  %xmm0,(%r12)
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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