#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 hamming(const int N, double *v) {
  int i;
  if (N == 1) {
    *v = 1.0;
    return;
  }
  for (i = 0; i < N; i++) {
    v[i] = 0.54 - 0.46 * cos(6.2831853071795864 * i / (N - 1));
  }
}


x86 assembly (clang, -O0):
<hamming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    113e <hamming+0x2e>
mov    -0x10(%rbp),%rax
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    11a8 <hamming+0x98>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a8 <hamming+0x98>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xeb2(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movsd  0xe83(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe7f(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <hamming+0x35>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hamming>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1132 <hamming+0x22>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%r14)
jmp    1224 <hamming+0x114>
jl     1224 <hamming+0x114>
lea    -0x1(%rdi),%eax
cvtsi2sd %eax,%xmm0
mov    %edi,%r15d
cmp    $0x1,%edi
jne    1158 <hamming+0x48>
xor    %ebx,%ebx
test   $0x1,%r15b
jne    11f2 <hamming+0xe2>
jmp    1224 <hamming+0x114>
mov    %r15d,%r12d
and    $0xfffffffe,%r12d
xor    %ebx,%ebx
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xe81(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  (%rsp),%xmm0
call   1030 <cos@plt>
movsd  0xe73(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe6f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe43(%rip),%xmm0
divsd  (%rsp),%xmm0
call   1030 <cos@plt>
mulsd  0xe39(%rip),%xmm0
addsd  0xe39(%rip),%xmm0
movsd  %xmm0,0x8(%r14,%rbx,8)
add    $0x2,%rbx
cmp    %r12,%rbx
jne    1170 <hamming+0x60>
movsd  (%rsp),%xmm0
test   $0x1,%r15b
je     1224 <hamming+0x114>
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xdfb(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
mulsd  0xdf2(%rip),%xmm0
addsd  0xdf2(%rip),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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