#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 cos(double);
double weierstrass(double x) {
  int n;
  double bt = 3;
  double at = 2;
  double a = 1;
  double b = 1;
  double sum = 0.0;
  for (n = 0; n < 100; n++) {
    sum = sum + ((1.0 / a) * cos(b * 3.14159265358979323846 * x));
    a = a * at;
    b = b * bt;
  }
  return sum;
}


x86 assembly (clang, -O0):
<weierstrass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xeeb(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xed6(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    11e3 <weierstrass+0xd3>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe84(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe8a(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1160 <weierstrass+0x50>
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weierstrass>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,0x28(%rsp)
movapd 0xedd(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x64,%ebx
nopl   0x0(%rax)
movsd  %xmm0,0x20(%rsp)
movapd %xmm1,(%rsp)
movapd (%rsp),%xmm2
unpckhpd %xmm2,%xmm2
movsd  0xed4(%rip),%xmm1
divsd  %xmm2,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd (%rsp),%xmm0
movsd  0xec5(%rip),%xmm1
mulsd  %xmm1,%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <cos@plt>
mulsd  0x18(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
movapd 0xe7f(%rip),%xmm1
mulpd  %xmm1,%xmm0
movapd %xmm0,(%rsp)
movapd (%rsp),%xmm0
unpckhpd %xmm0,%xmm0
movsd  0xe75(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd (%rsp),%xmm0
mulsd  0xe66(%rip),%xmm0
mulsd  0x28(%rsp),%xmm0
call   1030 <cos@plt>
movapd (%rsp),%xmm1
mulsd  0x18(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
mulpd  0xe2a(%rip),%xmm1
add    $0xfffffffe,%ebx
jne    1130 <weierstrass+0x20>
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @weierstrass(double %0) {
br label %2
2: ; preds = %2, %1
%3 = phi double [ 0.000000e+00, %1 ], [ %20, %2 ]
%4 = phi i32 [ 0, %1 ], [ %22, %2 ]
%5 = phi <2 x double> [ <double 1.000000e+00, double 1.000000e+00>, %1 ], [ %21, %2 ]
%6 = extractelement <2 x double> %5, i64 1
%7 = fdiv double 1.000000e+00, %6
%8 = extractelement <2 x double> %5, i64 0
%9 = fmul double %8, 0x400921FB54442D18
%10 = fmul double %9, %0
%11 = tail call double @cos(double %10)
%12 = tail call double @llvm.fmuladd.f64(double %7, double %11, double %3)
%13 = fmul <2 x double> %5, <double 3.000000e+00, double 2.000000e+00>
%14 = extractelement <2 x double> %13, i64 1
%15 = fdiv double 1.000000e+00, %14
%16 = extractelement <2 x double> %13, i64 0
%17 = fmul double %16, 0x400921FB54442D18
%18 = fmul double %17, %0
%19 = tail call double @cos(double %18)
%20 = tail call double @llvm.fmuladd.f64(double %15, double %19, double %12)
%21 = fmul <2 x double> %13, <double 3.000000e+00, double 2.000000e+00>
%22 = add nuw nsw i32 %4, 2
%23 = icmp eq i32 %22, 100
br i1 %23, label %24, label %2
24: ; preds = %2
ret double %20
}