#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);
void hamming(float *hamming, int N) {
  float M;
  int n;
  M = (N - 1) / 2;
  for (n = 0; n < N; n++) {
    hamming[n] =
        0.54 + 0.46 * cos((2 * 3.14159265359 * ((float)n - M)) / (2 * M + 1));
  }
}


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
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c0 <hamming+0xb0>
cvtsi2ssl -0x14(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xeb1(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x10(%rbp),%xmm1
addss  %xmm1,%xmm1
movss  0xea4(%rip),%xmm2
addss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  0xe6f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <hamming+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hamming>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11ab <hamming+0x9b>
mov    %rdi,%r14
lea    -0x1(%rsi),%eax
shr    $0x1f,%eax
add    %esi,%eax
add    $0xffffffff,%eax
sar    %eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
addss  %xmm0,%xmm0
addss  0xeb9(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %esi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
subss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe8f(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
mulsd  0xe80(%rip),%xmm0
addsd  0xe80(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <hamming+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @hamming(float* nocapture writeonly %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = sdiv i32 %3, 2
%5 = sitofp i32 %4 to float
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %26
7: ; preds = %2
%8 = tail call float @llvm.fmuladd.f32(float %5, float 2.000000e+00, float 1.000000e+00)
%9 = fpext float %8 to double
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %24, %11 ]
%13 = trunc i64 %12 to i32
%14 = sitofp i32 %13 to float
%15 = fsub float %14, %5
%16 = fpext float %15 to double
%17 = fmul double %16, 0x401921FB54442EEA
%18 = fdiv double %17, %9
%19 = fptosi double %18 to i32
%20 = tail call double @cos(i32 %19)
%21 = tail call double @llvm.fmuladd.f64(double %20, double 4.600000e-01, double 5.400000e-01)
%22 = fptrunc double %21 to float
%23 = getelementptr inbounds float, float* %0, i64 %12
store float %22, float* %23
%24 = add nuw nsw i64 %12, 1
%25 = icmp eq i64 %24, %10
br i1 %25, label %26, label %11
26: ; preds = %11, %2
ret void
}