#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(int);
double ComputAFitness(double X[]) {
  double ans = 0;
  for (int i = 0; i < 30; i++) {
    ans += X[i] * X[i] - 10 * cos(2 * 3.141592 * X[i]) + 10;
  }
  return ans + 3;
}


x86 assembly (clang, -O0):
<ComputAFitness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1e,-0x14(%rbp)
jge    11cb <ComputAFitness+0xbb>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  0xea7(%rip),%xmm0
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
imul   $0xa,%eax,%eax
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe59(%rip),%xmm1
addsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <ComputAFitness+0x1b>
movsd  0xe2d(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputAFitness>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%ebx
nopl   0x0(%rax)
movsd  -0x8(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xebb(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movsd  0xe94(%rip),%xmm0
addsd  %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0xe68(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
addsd  0xe45(%rip),%xmm1
addsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x2,%rbx
cmp    $0x1f,%rbx
jne    1130 <ComputAFitness+0x20>
movsd  0x8(%rsp),%xmm0
addsd  0xe25(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @ComputAFitness(double* %0) {
%2 = alloca double*
%3 = alloca double
%4 = alloca i32
store double* %0, double** %2
store double 0.000000e+00, double* %3
store i32 0, i32* %4
br label %5
5: ; preds = %34, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 30
br i1 %7, label %8, label %37
8: ; preds = %5
%9 = load double*, double** %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds double, double* %9, i64 %11
%13 = load double, double* %12
%14 = load double*, double** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fmul double 0x401921FAFC8B007A, %23
%25 = fptosi double %24 to i32
%26 = call i32 @cos(i32 %25)
%27 = mul nsw i32 10, %26
%28 = sitofp i32 %27 to double
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %13, double %18, double %29)
%31 = fadd double %30, 1.000000e+01
%32 = load double, double* %3
%33 = fadd double %32, %31
store double %33, double* %3
br label %34
34: ; preds = %8
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %5
37: ; preds = %5
%38 = load double, double* %3
%39 = fadd double %38, 3.000000e+00
ret double %39
}

LLVM IR (-O2):
define double @ComputAFitness(double* nocapture %0) {
br label %4
2: ; preds = %4
%3 = fadd double %29, 3.000000e+00
ret double %3
4: ; preds = %4, %1
%5 = phi i64 [ 0, %1 ], [ %30, %4 ]
%6 = phi double [ 0.000000e+00, %1 ], [ %29, %4 ]
%7 = getelementptr inbounds double, double* %0, i64 %5
%8 = load double, double* %7
%9 = fmul double %8, 0x401921FAFC8B007A
%10 = fptosi double %9 to i32
%11 = tail call i32 @cos(i32 %10)
%12 = mul nsw i32 %11, 10
%13 = sitofp i32 %12 to double
%14 = fneg double %13
%15 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %14)
%16 = fadd double %15, 1.000000e+01
%17 = fadd double %6, %16
%18 = or i64 %5, 1
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = fmul double %20, 0x401921FAFC8B007A
%22 = fptosi double %21 to i32
%23 = tail call i32 @cos(i32 %22)
%24 = mul nsw i32 %23, 10
%25 = sitofp i32 %24 to double
%26 = fneg double %25
%27 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %26)
%28 = fadd double %27, 1.000000e+01
%29 = fadd double %17, %28
%30 = add nuw nsw i64 %5, 2
%31 = icmp eq i64 %30, 30
br i1 %31, label %2, label %4
}