#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(double);
void apply_hamming_window(double coeffs[], int len) {
  double w;
  int i;
  int h;
  h = (len - 1) / 2;
  for (i = 1; i <= h; i++) {
    w = 0.53836 - 0.46164 * cos(2.0 * 3.1415926535 * (double)(h + i) /
                                (double)(len - 1.0));
    coeffs[h + i] *= w;
    coeffs[h - i] *= w;
  }
}


x86 assembly (clang, -O0):
<apply_hamming_window>:
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
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     11d6 <apply_hamming_window+0xc6>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xec3(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xeaa(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movsd  0xe85(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe81(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <apply_hamming_window+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_hamming_window>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%esi
jl     11d4 <apply_hamming_window+0xc4>
mov    %rdi,%r14
lea    -0x1(%rsi),%eax
shr    $0x1f,%eax
add    %esi,%eax
add    $0xffffffff,%eax
sar    %eax
cvtsi2sd %esi,%xmm0
addsd  0xebe(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movslq %eax,%r13
cmp    $0x2,%r13d
mov    $0x1,%eax
cmovge %r13d,%eax
add    $0x1,%eax
lea    (%rdi,%r13,8),%r15
add    $0xfffffffffffffff8,%r15
add    $0x1,%r13
mov    $0x1,%r12d
sub    %rax,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mulsd  0xe78(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
call   1030 <cos@plt>
mulsd  0xe6d(%rip),%xmm0
addsd  0xe6d(%rip),%xmm0
movsd  (%r14,%r13,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%r13,8)
mulsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0xffffffffffffffff,%rbx
add    $0x1,%r13
cmp    %rbx,%r12
jne    1180 <apply_hamming_window+0x70>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @apply_hamming_window(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = sdiv i32 %9, 2
store i32 %10, i32* %7
store i32 1, i32* %6
br label %11
11: ; preds = %45, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %48
15: ; preds = %11
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = add nsw i32 %16, %17
%19 = sitofp i32 %18 to double
%20 = fmul double 0x401921FB54411744, %19
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to double
%23 = fsub double %22, 1.000000e+00
%24 = fdiv double %20, %23
%25 = call double @cos(double %24)
%26 = call double @llvm.fmuladd.f64(double -4.616400e-01, double %25, double 5.383600e-01)
store double %26, double* %5
%27 = load double, double* %5
%28 = load double*, double** %3
%29 = load i32, i32* %7
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %28, i64 %32
%34 = load double, double* %33
%35 = fmul double %34, %27
store double %35, double* %33
%36 = load double, double* %5
%37 = load double*, double** %3
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = sub nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %37, i64 %41
%43 = load double, double* %42
%44 = fmul double %43, %36
store double %44, double* %42
br label %45
45: ; preds = %15
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %11
48: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @apply_hamming_window(double* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sdiv i32 %3, 2
%5 = icmp slt i32 %1, 3
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = sitofp i32 %1 to double
%8 = fadd double %7, -1.000000e+00
%9 = sext i32 %4 to i64
%10 = call i32 @llvm.smax.i32(i32 %4, i32 1)
%11 = add nuw nsw i32 %10, 1
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %6, %13
%14 = phi i64 [ 1, %6 ], [ %29, %13 ]
%15 = add nsw i64 %14, %9
%16 = trunc i64 %15 to i32
%17 = sitofp i32 %16 to double
%18 = fmul double %17, 0x401921FB54411744
%19 = fdiv double %18, %8
%20 = tail call double @cos(double %19)
%21 = tail call double @llvm.fmuladd.f64(double %20, double -4.616400e-01, double 5.383600e-01)
%22 = getelementptr inbounds double, double* %0, i64 %15
%23 = load double, double* %22
%24 = fmul double %23, %21
store double %24, double* %22
%25 = sub nsw i64 %9, %14
%26 = getelementptr inbounds double, double* %0, i64 %25
%27 = load double, double* %26
%28 = fmul double %21, %27
store double %28, double* %26
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %13
31: ; preds = %13, %2
ret void
}