#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 sin(int);
void makeweights(int bw, double *weights) {
  const double pi = 3.141592653589793238462643383279502884197;
  const double fudge = pi / (4 * bw);
  int j;
  for (j = 0; j < 2 * bw; ++j) {
    double tmpsum = 0;
    int k;
    for (k = 0; k < bw; ++k)
      tmpsum += 1. / (2 * k + 1) * sin((2 * j + 1) * (2 * k + 1) * fudge);
    tmpsum *= sin((2 * j + 1) * fudge);
    tmpsum *= 2. / bw;
    weights[j] = tmpsum;
  }
}


x86 assembly (clang, -O0):
<makeweights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xed9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x2,%eax
cvtsi2sd %eax,%xmm1
movsd  0xec2(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    1247 <makeweights+0x137>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e7 <makeweights+0xd7>
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe81(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116e <makeweights+0x5e>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xdef(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <makeweights+0x3e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeweights>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,0x38(%rsp)
mov    %rdi,0x18(%rsp)
test   %edi,%edi
jle    125c <makeweights+0x14c>
mov    0x18(%rsp),%rcx
lea    0x0(,%rcx,4),%eax
cvtsi2sd %eax,%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
lea    (%rcx,%rcx,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xea4(%rip),%xmm1
cmp    $0x2,%eax
mov    $0x1,%r15d
cmovl  %r15d,%eax
mov    %rax,0x30(%rsp)
divsd  %xmm0,%xmm1
movsd  %xmm1,0x28(%rsp)
mov    $0x2,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbp,%rbp,1),%eax
mov    %eax,0x14(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15d,%r13d
mov    $0x1,%r12d
mov    0x18(%rsp),%rax
mov    %eax,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
movsd  0xe40(%rip),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %r13d,%xmm1
divsd  %xmm0,%xmm2
movsd  %xmm2,0x40(%rsp)
mulsd  0x20(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1030 <sin@plt>
mulsd  0x40(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x2,%r12d
add    %ebx,%r13d
add    $0xffffffff,%r14d
jne    11c0 <makeweights+0xb0>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0x28(%rsp),%xmm1
mov    0x38(%rsp),%rax
movsd  %xmm1,(%rax,%rbp,8)
add    $0x1,%rbp
add    $0x2,%r15d
add    $0x4,%ebx
cmp    0x30(%rsp),%rbp
jne    1190 <makeweights+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @makeweights(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store i32 %0, i32* %3
store double* %1, double** %4
store double 0x400921FB54442D18, double* %5
%10 = load i32, i32* %3
%11 = mul nsw i32 4, %10
%12 = sitofp i32 %11 to double
%13 = fdiv double 0x400921FB54442D18, %12
store double %13, double* %6
store i32 0, i32* %7
br label %14
14: ; preds = %68, %2
%15 = load i32, i32* %7
%16 = load i32, i32* %3
%17 = mul nsw i32 2, %16
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %71
19: ; preds = %14
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %20
20: ; preds = %44, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = load i32, i32* %9
%26 = mul nsw i32 2, %25
%27 = add nsw i32 %26, 1
%28 = sitofp i32 %27 to double
%29 = fdiv double 1.000000e+00, %28
%30 = load i32, i32* %7
%31 = mul nsw i32 2, %30
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %9
%34 = mul nsw i32 2, %33
%35 = add nsw i32 %34, 1
%36 = mul nsw i32 %32, %35
%37 = sitofp i32 %36 to double
%38 = load double, double* %6
%39 = fmul double %37, %38
%40 = fptosi double %39 to i32
%41 = call double @sin(i32 %40)
%42 = load double, double* %8
%43 = call double @llvm.fmuladd.f64(double %29, double %41, double %42)
store double %43, double* %8
br label %44
44: ; preds = %24
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %20
47: ; preds = %20
%48 = load i32, i32* %7
%49 = mul nsw i32 2, %48
%50 = add nsw i32 %49, 1
%51 = sitofp i32 %50 to double
%52 = load double, double* %6
%53 = fmul double %51, %52
%54 = fptosi double %53 to i32
%55 = call double @sin(i32 %54)
%56 = load double, double* %8
%57 = fmul double %56, %55
store double %57, double* %8
%58 = load i32, i32* %3
%59 = sitofp i32 %58 to double
%60 = fdiv double 2.000000e+00, %59
%61 = load double, double* %8
%62 = fmul double %61, %60
store double %62, double* %8
%63 = load double, double* %8
%64 = load double*, double** %4
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
store double %63, double* %67
br label %68
68: ; preds = %47
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %14
71: ; preds = %14
ret void
}

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