#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 translate(unsigned short, double);
double rastrigin(unsigned short (*pop)[20]) {
  double res = 3.0 * 20;
  double val;
  for (int i = 0; i < 20; i++) {
    val = translate((*pop)[i], 5.12);
    res += (val * val) - (3.0 * cos(2.0 * 3.141593 * val));
  }
  return res;
}


x86 assembly (clang, -O0):
<rastrigin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  0xecc(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jge    11de <rastrigin+0xbe>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xebe(%rip),%xmm0
movzwl (%rax,%rcx,2),%edi
call   1040 <translate@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe8c(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1030 <cos@plt>
movsd  -0x30(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x28(%rbp),%xmm0
movsd  0xe65(%rip),%xmm1
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <rastrigin+0x20>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rastrigin>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movsd  0xece(%rip),%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x10(%rsp)
movzwl (%r14,%rbx,2),%edi
movsd  0xeb5(%rip),%xmm0
call   1040 <translate@plt>
movsd  %xmm0,0x8(%rsp)
mulsd  0xeaa(%rip),%xmm0
call   1030 <cos@plt>
mulsd  0xea5(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    1140 <rastrigin+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @rastrigin([20 x i16]* %0) {
%2 = alloca [20 x i16]*
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store [20 x i16]* %0, [20 x i16]** %2
store double 6.000000e+01, double* %3
store i32 0, i32* %5
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 20
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = load [20 x i16]*, [20 x i16]** %2
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [20 x i16], [20 x i16]* %10, i64 0, i64 %12
%14 = load i16, i16* %13
%15 = call double @translate(i16 zeroext %14, double 5.120000e+00)
store double %15, double* %4
%16 = load double, double* %4
%17 = load double, double* %4
%18 = load double, double* %4
%19 = fmul double 0x401921FB82C2BD7F, %18
%20 = call double @cos(double %19)
%21 = fmul double 3.000000e+00, %20
%22 = fneg double %21
%23 = call double @llvm.fmuladd.f64(double %16, double %17, double %22)
%24 = load double, double* %3
%25 = fadd double %24, %23
store double %25, double* %3
br label %26
26: ; preds = %9
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %6
29: ; preds = %6
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
define double @rastrigin([20 x i16]* nocapture %0) {
br label %3
2: ; preds = %3
ret double %13
3: ; preds = %1, %3
%4 = phi i64 [ 0, %1 ], [ %14, %3 ]
%5 = phi double [ 6.000000e+01, %1 ], [ %13, %3 ]
%6 = getelementptr inbounds [20 x i16], [20 x i16]* %0, i64 0, i64 %4
%7 = load i16, i16* %6
%8 = tail call double @translate(i16 zeroext %7, double 5.120000e+00)
%9 = fmul double %8, 0x401921FB82C2BD7F
%10 = tail call double @cos(double %9)
%11 = fmul double %10, -3.000000e+00
%12 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %11)
%13 = fadd double %5, %12
%14 = add nuw nsw i64 %4, 1
%15 = icmp eq i64 %14, 20
br i1 %15, label %2, label %3
}