#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(double);
double pow(double, double);
double sqrt(double);
double griewank(double sol[], int DIM) {
  int j;
  double top = 0.00, top1 = 0.00, top2 = 0.00;
  for (j = 0; j < DIM; j++) {
    top1 = top1 + pow((sol[j]), (double)2);
    top2 = top2 * cos((((sol[j]) / sqrt((double)(j + 1))) * M_PI) / 180);
  }
  top = (1 / (double)4000) * top1 - top2 + 1;
  return top;
}


x86 assembly (clang, -O0):
<griewank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1211 <griewank+0xe1>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe8f(%rip),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    0x2e0b(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe27(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115e <griewank+0x2e>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdce(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdb6(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<griewank>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    11d8 <griewank+0xb8>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
mov    0x2ea6(%rip),%r12
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
jmp    11b1 <griewank+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm3,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
movsd  (%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rsp)
divsd  %xmm0,%xmm3
mulsd  (%r12),%xmm3
divsd  0xe67(%rip),%xmm3
movapd %xmm3,%xmm0
call   1030 <cos@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
cmp    %rbx,%r15
je     11e5 <griewank+0xc5>
movsd  %xmm1,0x10(%rsp)
movsd  (%r14,%rbx,8),%xmm3
add    $0x1,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
ucomisd 0xe48(%rip),%xmm0
jb     1160 <griewank+0x40>
sqrtsd %xmm0,%xmm0
jmp    1171 <griewank+0x51>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm0
mulsd  0xe16(%rip),%xmm0
subsd  %xmm1,%xmm0
addsd  0xe12(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @griewank(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %5
br label %9
9: ; preds = %38, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %41
13: ; preds = %9
%14 = load double, double* %7
%15 = load double*, double** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = call double @pow(double %19, double 2.000000e+00)
%21 = fadd double %14, %20
store double %21, double* %7
%22 = load double, double* %8
%23 = load double*, double** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
%30 = sitofp i32 %29 to double
%31 = call double @sqrt(double %30)
%32 = fdiv double %27, %31
%33 = load double, double* @M_PI
%34 = fmul double %32, %33
%35 = fdiv double %34, 1.800000e+02
%36 = call double @cos(double %35)
%37 = fmul double %22, %36
store double %37, double* %8
br label %38
38: ; preds = %13
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %9
41: ; preds = %9
%42 = load double, double* %7
%43 = load double, double* %8
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double 2.500000e-04, double %42, double %44)
%46 = fadd double %45, 1.000000e+00
store double %46, double* %6
%47 = load double, double* %6
ret double %47
}

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