#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 cos(int);
double *hamming(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.54 - 0.46 * cos(i * arg);
  return (w);
}


x86 assembly (clang, -O0):
<hamming>:
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    11a1 <hamming+0x91>
cvtsi2sdl -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  0xe98(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe94(%rip),%xmm1
addsd  %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 <hamming+0x39>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hamming>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
test   %esi,%esi
jle    1226 <hamming+0x116>
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     11fd <hamming+0xed>
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>
movsd  0xe79(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe75(%rip),%xmm1
addsd  %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
mulsd  0xe38(%rip),%xmm0
addsd  0xe38(%rip),%xmm0
movsd  %xmm0,0x8(%r12)
add    $0x10,%r12
addsd  0xe2d(%rip),%xmm2
add    $0x2,%ebx
cmp    %ebx,%ebp
jne    1170 <hamming+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
test   $0x1,%r15b
je     1226 <hamming+0x116>
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <cos@plt>
mulsd  0xdf0(%rip),%xmm0
addsd  0xdf0(%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* @hamming(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 = %27, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
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 double @cos(i32 %22)
%24 = call double @llvm.fmuladd.f64(double -4.600000e-01, double %23, double 5.400000e-01)
%25 = load double*, double** %7
%26 = getelementptr inbounds double, double* %25, i32 1
store double* %26, double** %7
store double %24, double* %25
br label %27
27: ; preds = %17
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %13
30: ; preds = %13
%31 = load double*, double** %3
ret double* %31
}

LLVM IR (-O2):
define double* @hamming(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 %43
7: ; preds = %2
%8 = and i32 %1, 1
%9 = icmp eq i32 %1, 1
br i1 %9, label %34, label %10
10: ; preds = %7
%11 = and i32 %1, -2
br label %12
12: ; preds = %12, %10
%13 = phi double* [ %0, %10 ], [ %28, %12 ]
%14 = phi i32 [ 0, %10 ], [ %29, %12 ]
%15 = phi i32 [ 0, %10 ], [ %30, %12 ]
%16 = sitofp i32 %14 to double
%17 = fmul double %5, %16
%18 = fptosi double %17 to i32
%19 = tail call double @cos(i32 %18)
%20 = tail call double @llvm.fmuladd.f64(double %19, double -4.600000e-01, double 5.400000e-01)
%21 = getelementptr inbounds double, double* %13, i64 1
store double %20, double* %13
%22 = or i32 %14, 1
%23 = sitofp i32 %22 to double
%24 = fmul double %5, %23
%25 = fptosi double %24 to i32
%26 = tail call double @cos(i32 %25)
%27 = tail call double @llvm.fmuladd.f64(double %26, double -4.600000e-01, double 5.400000e-01)
%28 = getelementptr inbounds double, double* %13, i64 2
store double %27, double* %21
%29 = add nuw nsw i32 %14, 2
%30 = add i32 %15, 2
%31 = icmp eq i32 %30, %11
br i1 %31, label %32, label %12
32: ; preds = %12
%33 = sitofp i32 %29 to double
br label %34
34: ; preds = %32, %7
%35 = phi double* [ %0, %7 ], [ %28, %32 ]
%36 = phi double [ 0.000000e+00, %7 ], [ %33, %32 ]
%37 = icmp eq i32 %8, 0
br i1 %37, label %43, label %38
38: ; preds = %34
%39 = fmul double %5, %36
%40 = fptosi double %39 to i32
%41 = tail call double @cos(i32 %40)
%42 = tail call double @llvm.fmuladd.f64(double %41, double -4.600000e-01, double 5.400000e-01)
store double %42, double* %35
br label %43
43: ; preds = %38, %34, %2
ret double* %0
}