#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 M_PI;
int cos(int);
int pow(double, double);
double rastrigin(double sol[], int DIM) {
  int j;
  double top = 0.00;
  for (j = 0; j < DIM; j++) {
    top = top + (pow(sol[j], (double)2) - 10 * cos(2 * M_PI * sol[j]) + 10);
  }
  return top;
}


x86 assembly (clang, -O0):
<rastrigin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c4 <rastrigin+0xa4>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe97(%rip),%xmm1
call   1040 <pow@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  -0x28(%rbp),%xmm0
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   $0xa,%ecx,%ecx
sub    %ecx,%eax
add    $0xa,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113e <rastrigin+0x1e>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rastrigin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    11bd <rastrigin+0x9d>
mov    %rdi,%r14
mov    %esi,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
mov    0x2ea1(%rip),%r13
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%rbx,8),%xmm0
movsd  0xe9c(%rip),%xmm1
call   1040 <pow@plt>
mov    %eax,%r12d
mov    0x0(%r13),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  (%r14,%rbx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
add    %r12d,%eax
add    $0xa,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <rastrigin+0x30>
jmp    11c0 <rastrigin+0xa0>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@M_PI = global i32 0
define double @rastrigin(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %24, %6 ]
%8 = phi double [ 0.000000e+00, %4 ], [ %23, %6 ]
%9 = getelementptr inbounds double, double* %0, i64 %7
%10 = load double, double* %9
%11 = tail call i32 @pow(double %10, double 2.000000e+00)
%12 = load i32, i32* @M_PI
%13 = shl nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = load double, double* %9
%16 = fmul double %15, %14
%17 = fptosi double %16 to i32
%18 = tail call i32 @cos(i32 %17)
%19 = mul i32 %18, -10
%20 = add i32 %11, 10
%21 = add i32 %20, %19
%22 = sitofp i32 %21 to double
%23 = fadd double %8, %22
%24 = add nuw nsw i64 %7, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %6
26: ; preds = %6, %2
%27 = phi double [ 0.000000e+00, %2 ], [ %23, %6 ]
ret double %27
}