#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 */
int M_PI;
double cos(double);
double sin(double);
double cis_sum_real(double phase, double sharpness, int num_coefs,
                    double *coefs) {
  phase *= 2 * M_PI;
  double x = cos(phase) * sharpness;
  double y = sin(phase) * sharpness;
  double result_x = coefs[num_coefs - 1];
  double result_y = 0;
  for (int i = num_coefs - 2; 1; i--) {
    phase = result_x;
    result_x = result_x * x - result_y * y;
    result_x += coefs[i];
    if (i <= 0) {
      return result_x;
    }
    result_y = phase * y + result_y * x;
  }
  return result_x;
}


x86 assembly (clang, -O0):
<cis_sum_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
mov    %rsi,-0x28(%rbp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x4c(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    11b2 <cis_sum_real+0x92>
jmp    1253 <cis_sum_real+0x133>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jg     1224 <cis_sum_real+0x104>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    125d <cis_sum_real+0x13d>
movsd  -0x10(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
jmp    11a3 <cis_sum_real+0x83>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cis_sum_real>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  %xmm1,(%rsp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x8(%rsp),%xmm5
mulsd  (%rsp),%xmm0
movslq %ebp,%rax
movsd  -0x8(%rbx,%rax,8),%xmm2
movsd  0xe7d(%rip),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm2,%xmm1
mulsd  %xmm5,%xmm1
addsd  %xmm3,%xmm1
addsd  -0x10(%rbx,%rax,8),%xmm1
cmp    $0x3,%eax
jl     11e4 <cis_sum_real+0xc4>
mov    %ebp,%eax
add    $0xffffffffffffffff,%rax
xorpd  %xmm3,%xmm3
nopl   0x0(%rax,%rax,1)
movapd %xmm1,%xmm4
mulsd  %xmm5,%xmm3
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm3
movapd %xmm0,%xmm2
mulsd  %xmm3,%xmm2
mulsd  %xmm5,%xmm1
subsd  %xmm2,%xmm1
addsd  -0x10(%rbx,%rax,8),%xmm1
add    $0xffffffffffffffff,%rax
movapd %xmm4,%xmm2
cmp    $0x1,%rax
ja     11b0 <cis_sum_real+0x90>
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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