#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 cos(double);
double func(double x) {
  double ret = 2. / 2 * 3.14159265;
  int i;
  for (i = 1; i < 10; i++) {
    ret += 2. / 2 * 3.14159265 * cos(x * 2 * 3.14159265 * i / 2 * 3.14159265);
  };
  return ret;
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xedb(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11a6 <func+0x96>
movsd  0xec5(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe8f(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
cvtsi2sd %eax,%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe75(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <func+0x21>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
sub    $0x18,%rsp
addsd  %xmm0,%xmm0
movsd  0xee0(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xed6(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xeb6(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm0
mulsd  0xe9e(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe7e(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe76(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xe60(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe40(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe40(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xe22(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe02(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe0a(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xde4(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xdc4(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xdd4(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xda6(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xd86(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xd9e(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xd68(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xd48(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xd68(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xd2a(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xd0a(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xd2c(%rip),%xmm0
mulsd  0xcec(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xccc(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @func(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double %0, double* %2
store double 0x400921FB53C8D4F1, double* %3
store i32 1, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = load double, double* %2
%10 = fmul double %9, 2.000000e+00
%11 = fmul double %10, 0x400921FB53C8D4F1
%12 = load i32, i32* %4
%13 = sitofp i32 %12 to double
%14 = fmul double %11, %13
%15 = fdiv double %14, 2.000000e+00
%16 = fmul double %15, 0x400921FB53C8D4F1
%17 = call i32 @cos(double %16)
%18 = sitofp i32 %17 to double
%19 = load double, double* %3
%20 = call double @llvm.fmuladd.f64(double 0x400921FB53C8D4F1, double %18, double %19)
store double %20, double* %3
br label %21
21: ; preds = %8
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %5
24: ; preds = %5
%25 = load double, double* %3
ret double %25
}

LLVM IR (-O2):
define double @func(double %0) {
%2 = fmul double %0, 2.000000e+00
%3 = fmul double %2, 0x400921FB53C8D4F1
%4 = fmul double %3, 5.000000e-01
%5 = fmul double %4, 0x400921FB53C8D4F1
%6 = tail call i32 @cos(double %5)
%7 = sitofp i32 %6 to double
%8 = tail call double @llvm.fmuladd.f64(double %7, double 0x400921FB53C8D4F1, double 0x400921FB53C8D4F1)
%9 = fmul double %3, 2.000000e+00
%10 = fmul double %9, 5.000000e-01
%11 = fmul double %10, 0x400921FB53C8D4F1
%12 = tail call i32 @cos(double %11)
%13 = sitofp i32 %12 to double
%14 = tail call double @llvm.fmuladd.f64(double %13, double 0x400921FB53C8D4F1, double %8)
%15 = fmul double %3, 3.000000e+00
%16 = fmul double %15, 5.000000e-01
%17 = fmul double %16, 0x400921FB53C8D4F1
%18 = tail call i32 @cos(double %17)
%19 = sitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double 0x400921FB53C8D4F1, double %14)
%21 = fmul double %3, 4.000000e+00
%22 = fmul double %21, 5.000000e-01
%23 = fmul double %22, 0x400921FB53C8D4F1
%24 = tail call i32 @cos(double %23)
%25 = sitofp i32 %24 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 0x400921FB53C8D4F1, double %20)
%27 = fmul double %3, 5.000000e+00
%28 = fmul double %27, 5.000000e-01
%29 = fmul double %28, 0x400921FB53C8D4F1
%30 = tail call i32 @cos(double %29)
%31 = sitofp i32 %30 to double
%32 = tail call double @llvm.fmuladd.f64(double %31, double 0x400921FB53C8D4F1, double %26)
%33 = fmul double %3, 6.000000e+00
%34 = fmul double %33, 5.000000e-01
%35 = fmul double %34, 0x400921FB53C8D4F1
%36 = tail call i32 @cos(double %35)
%37 = sitofp i32 %36 to double
%38 = tail call double @llvm.fmuladd.f64(double %37, double 0x400921FB53C8D4F1, double %32)
%39 = fmul double %3, 7.000000e+00
%40 = fmul double %39, 5.000000e-01
%41 = fmul double %40, 0x400921FB53C8D4F1
%42 = tail call i32 @cos(double %41)
%43 = sitofp i32 %42 to double
%44 = tail call double @llvm.fmuladd.f64(double %43, double 0x400921FB53C8D4F1, double %38)
%45 = fmul double %3, 8.000000e+00
%46 = fmul double %45, 5.000000e-01
%47 = fmul double %46, 0x400921FB53C8D4F1
%48 = tail call i32 @cos(double %47)
%49 = sitofp i32 %48 to double
%50 = tail call double @llvm.fmuladd.f64(double %49, double 0x400921FB53C8D4F1, double %44)
%51 = fmul double %3, 9.000000e+00
%52 = fmul double %51, 5.000000e-01
%53 = fmul double %52, 0x400921FB53C8D4F1
%54 = tail call i32 @cos(double %53)
%55 = sitofp i32 %54 to double
%56 = tail call double @llvm.fmuladd.f64(double %55, double 0x400921FB53C8D4F1, double %50)
ret double %56
}