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


x86 assembly (clang, -O0):
<makeweights2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ec2(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x4(%rbp),%eax
shl    $0x2,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    1235 <makeweights2+0x125>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d9 <makeweights2+0xc9>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe83(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <makeweights2+0x54>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <sin@plt>
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xdf9(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%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    1144 <makeweights2+0x34>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeweights2>:
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    1254 <makeweights2+0x144>
mov    0x2eb1(%rip),%rax
movsd  (%rax),%xmm1
mov    0x18(%rsp),%rcx
lea    0x0(,%rcx,4),%eax
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
lea    (%rcx,%rcx,1),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0xe99(%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  0xe38(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x40(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mulsd  0x20(%rsp),%xmm0
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 <makeweights2+0xb0>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
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 <makeweights2+0x80>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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