#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 *tml_dr_Malloc(int);
void tml_dr_WinHamming(double *vec, int N) {
  int i;
  double *w = tml_dr_Malloc(N);
  for (i = 0; i < N; i++) {
    w[i] = 0.54 -
           0.46 * cos(2 * (3.141592653589793115997963468544185161590576171875) *
                      i / N);
    vec[i - (N - 1) / 2] *= w[i];
  }
}


x86 assembly (clang, -O0):
<tml_dr_WinHamming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <tml_dr_Malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11df <tml_dr_WinHamming+0xbf>
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xeb5(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movsd  0xe87(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe83(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x20(%rbp),%rax
sub    %edx,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <tml_dr_WinHamming+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tml_dr_WinHamming>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%edi
call   1030 <tml_dr_Malloc@plt>
test   %r15d,%r15d
jle    11a8 <tml_dr_WinHamming+0x88>
mov    %rax,%r12
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,(%rsp)
lea    -0x1(%r15),%eax
shr    %eax
mov    %r15d,%r15d
neg    %eax
cltq
lea    (%r14,%rax,8),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xe91(%rip),%xmm0
divsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mulsd  0xe83(%rip),%xmm0
addsd  0xe83(%rip),%xmm0
movsd  %xmm0,(%r12,%rbx,8)
mulsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <tml_dr_WinHamming+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @tml_dr_WinHamming(double* nocapture %0, i32 %1) {
%3 = tail call double* @tml_dr_Malloc(i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = sitofp i32 %1 to double
%7 = add nsw i32 %1, -1
%8 = lshr i32 %7, 1
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %25, %10 ]
%12 = trunc i64 %11 to i32
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 0x401921FB54442D18
%15 = fdiv double %14, %6
%16 = fptosi double %15 to i32
%17 = tail call double @cos(i32 %16)
%18 = tail call double @llvm.fmuladd.f64(double %17, double -4.600000e-01, double 5.400000e-01)
%19 = getelementptr inbounds double, double* %3, i64 %11
store double %18, double* %19
%20 = sub i32 %12, %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %0, i64 %21
%23 = load double, double* %22
%24 = fmul double %18, %23
store double %24, double* %22
%25 = add nuw nsw i64 %11, 1
%26 = icmp eq i64 %25, %9
br i1 %26, label %27, label %10
27: ; preds = %10, %2
ret void
}