#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 cos(int);
double cosine_sum(double, int, double *);
int /*<<< orphan*/ printf(char *, double, double);
int main() {
  double coefs[] = {1, 3, 5, 6, 2};
  printf("%g %g\n", cosine_sum(0, 0, coefs), cosine_sum(0, 1, coefs));
  printf("%g = %g\n", 1 + 3 * cos(M_PI * 0.2), cosine_sum(0.1, 2, coefs));
  for (double p = 0; p < 1; p += 0.1) {
    double s = 0;
    for (int i = 0; i < 5; i++) {
      s += cos(2 * M_PI * p * i) * coefs[i];
    }
    printf("%g = %g\n", s, cosine_sum(p, 5, coefs));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeaf(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe9a(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    -0x30(%rbp),%rsi
xorps  %xmm0,%xmm0
xor    %edi,%edi
call   1050 <cosine_sum@plt>
movsd  %xmm0,-0x58(%rbp)
lea    -0x30(%rbp),%rsi
xorps  %xmm0,%xmm0
mov    $0x1,%edi
call   1050 <cosine_sum@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe38(%rip),%xmm0
mov    0x2e01(%rip),%rax
mulsd  (%rax),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <cos@plt>
movsd  0xe0c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe08(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
lea    -0x30(%rbp),%rsi
movsd  0xde3(%rip),%xmm0
mov    $0x2,%edi
call   1050 <cosine_sum@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdc5(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    130b <main+0x1cb>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x5,-0x44(%rbp)
jge    12c3 <main+0x183>
movsd  0xda9(%rip),%xmm0
mov    0x2d6a(%rip),%rax
mulsd  (%rax),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <cos@plt>
movslq -0x44(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1265 <main+0x125>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    -0x30(%rbp),%rsi
mov    $0x5,%edi
call   1050 <cosine_sum@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
lea    0xd50(%rip),%rdi
call   1030 <printf@plt>
movsd  0xd04(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1243 <main+0x103>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x4000000000000000,%rax
mov    %rax,0x30(%rsp)
lea    0x10(%rsp),%r14
xorps  %xmm0,%xmm0
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <cosine_sum@plt>
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <cosine_sum@plt>
movaps %xmm0,%xmm1
lea    0xebf(%rip),%rdi
movsd  (%rsp),%xmm0
call   1030 <printf@plt>
mov    0x2e46(%rip),%rbx
movsd  (%rbx),%xmm0
mulsd  0xe72(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  0xe69(%rip),%xmm0
addsd  0xe69(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe64(%rip),%xmm0
mov    $0x2,%edi
mov    %r14,%rsi
call   1040 <cosine_sum@plt>
movapd %xmm0,%xmm1
lea    0xe6b(%rip),%r15
mov    %r15,%rdi
movsd  (%rsp),%xmm0
call   1030 <printf@plt>
xorpd  %xmm1,%xmm1
nopl   (%rax)
movsd  %xmm1,(%rsp)
movsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0xe18(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
mulsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  0x20(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
mulsd  (%rsp),%xmm0
mulsd  0xd89(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  0x28(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx),%xmm0
addsd  %xmm0,%xmm0
mulsd  (%rsp),%xmm0
mulsd  0xd71(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  0x30(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mov    $0x5,%edi
mov    %r14,%rsi
call   1040 <cosine_sum@plt>
movaps %xmm0,%xmm1
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
movsd  (%rsp),%xmm1
addsd  0xd1e(%rip),%xmm1
movsd  0xd0e(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1200 <main+0xd0>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%g %g\0A\00"
@.str.1 = [9 x i8] c"%g = %g\0A\00"
@M_PI = global double 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x double]
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [5 x double]* %2 to i8*
%7 = bitcast i8* %6 to [5 x double]*
%8 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 0
store double 1.000000e+00, double* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 1
store double 3.000000e+00, double* %9
%10 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 2
store double 5.000000e+00, double* %10
%11 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 3
store double 6.000000e+00, double* %11
%12 = getelementptr inbounds [5 x double], [5 x double]* %7, i32 0, i32 4
store double 2.000000e+00, double* %12
%13 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%14 = call double @cosine_sum(double 0.000000e+00, i32 0, double* %13)
%15 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%16 = call double @cosine_sum(double 0.000000e+00, i32 1, double* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %14, double %16)
%18 = load double, double* @M_PI
%19 = fmul double %18, 2.000000e-01
%20 = fptosi double %19 to i32
%21 = call double @cos(i32 %20)
%22 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %21, double 1.000000e+00)
%23 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%24 = call double @cosine_sum(double 1.000000e-01, i32 2, double* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %22, double %24)
store double 0.000000e+00, double* %3
br label %26
26: ; preds = %58, %0
%27 = load double, double* %3
%28 = fcmp olt double %27, 1.000000e+00
br i1 %28, label %29, label %61
29: ; preds = %26
store double 0.000000e+00, double* %4
store i32 0, i32* %5
br label %30
30: ; preds = %49, %29
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 5
br i1 %32, label %33, label %52
33: ; preds = %30
%34 = load double, double* @M_PI
%35 = fmul double 2.000000e+00, %34
%36 = load double, double* %3
%37 = fmul double %35, %36
%38 = load i32, i32* %5
%39 = sitofp i32 %38 to double
%40 = fmul double %37, %39
%41 = fptosi double %40 to i32
%42 = call double @cos(i32 %41)
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 %44
%46 = load double, double* %45
%47 = load double, double* %4
%48 = call double @llvm.fmuladd.f64(double %42, double %46, double %47)
store double %48, double* %4
br label %49
49: ; preds = %33
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %30
52: ; preds = %30
%53 = load double, double* %4
%54 = load double, double* %3
%55 = getelementptr inbounds [5 x double], [5 x double]* %2, i64 0, i64 0
%56 = call double @cosine_sum(double %54, i32 5, double* %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %53, double %56)
br label %58
58: ; preds = %52
%59 = load double, double* %3
%60 = fadd double %59, 1.000000e-01
store double %60, double* %3
br label %26
61: ; preds = %26
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [7 x i8] c"%g %g\0A\00"
@.str.1 = [9 x i8] c"%g = %g\0A\00"
@M_PI = global double 0.000000e+00
define i32 @main() {
%1 = alloca [5 x double]
%2 = bitcast [5 x double]* %1 to i8*
%3 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 0
%4 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 1
%5 = bitcast [5 x double]* %1 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 3.000000e+00>, <2 x double>* %5
%6 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 2
%7 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 3
%8 = bitcast double* %6 to <2 x double>*
store <2 x double> <double 5.000000e+00, double 6.000000e+00>, <2 x double>* %8
%9 = getelementptr inbounds [5 x double], [5 x double]* %1, i64 0, i64 4
store double 2.000000e+00, double* %9
%10 = call double @cosine_sum(double 0.000000e+00, i32 0, double* %3)
%11 = call double @cosine_sum(double 0.000000e+00, i32 1, double* %3)
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %10, double %11)
%13 = load double, double* @M_PI
%14 = fmul double %13, 2.000000e-01
%15 = fptosi double %14 to i32
%16 = call double @cos(i32 %15)
%17 = call double @llvm.fmuladd.f64(double %16, double 3.000000e+00, double 1.000000e+00)
%18 = call double @cosine_sum(double 1.000000e-01, i32 2, double* %3)
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %17, double %18)
br label %20
20: ; preds = %0, %20
%21 = phi double [ 0.000000e+00, %0 ], [ %63, %20 ]
%22 = load double, double* @M_PI
%23 = fmul double %22, 2.000000e+00
%24 = fmul double %21, %23
%25 = fmul double %24, 0.000000e+00
%26 = fptosi double %25 to i32
%27 = call double @cos(i32 %26)
%28 = load double, double* %3
%29 = call double @llvm.fmuladd.f64(double %27, double %28, double 0.000000e+00)
%30 = load double, double* @M_PI
%31 = fmul double %30, 2.000000e+00
%32 = fmul double %21, %31
%33 = fptosi double %32 to i32
%34 = call double @cos(i32 %33)
%35 = load double, double* %4
%36 = call double @llvm.fmuladd.f64(double %34, double %35, double %29)
%37 = load double, double* @M_PI
%38 = fmul double %37, 2.000000e+00
%39 = fmul double %21, %38
%40 = fmul double %39, 2.000000e+00
%41 = fptosi double %40 to i32
%42 = call double @cos(i32 %41)
%43 = load double, double* %6
%44 = call double @llvm.fmuladd.f64(double %42, double %43, double %36)
%45 = load double, double* @M_PI
%46 = fmul double %45, 2.000000e+00
%47 = fmul double %21, %46
%48 = fmul double %47, 3.000000e+00
%49 = fptosi double %48 to i32
%50 = call double @cos(i32 %49)
%51 = load double, double* %7
%52 = call double @llvm.fmuladd.f64(double %50, double %51, double %44)
%53 = load double, double* @M_PI
%54 = fmul double %53, 2.000000e+00
%55 = fmul double %21, %54
%56 = fmul double %55, 4.000000e+00
%57 = fptosi double %56 to i32
%58 = call double @cos(i32 %57)
%59 = load double, double* %9
%60 = call double @llvm.fmuladd.f64(double %58, double %59, double %52)
%61 = call double @cosine_sum(double %21, i32 5, double* %3)
%62 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %60, double %61)
%63 = fadd double %21, 1.000000e-01
%64 = fcmp olt double %63, 1.000000e+00
br i1 %64, label %20, label %65
65: ; preds = %20
ret i32 0
}