#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 */
scalar_t__ cos(double);
double exp(double);
double sqrt(double);
double translate(unsigned short, int);
double ackley(unsigned short (*pop)[30]) {
  double res = 20.0 + exp(1.0);
  double e1 = 0;
  double e2 = 0;
  double member = 0;
  for (int i = 0; i < 30; i++) {
    member = translate((*pop)[i], 30);
    e1 += member * member;
    e2 += cos(2.0 * 3.141593 * member);
  }
  e2 = exp(e2 * 1.0 / (double)30);
  e1 = exp(-0.2 * sqrt(e1 * 1.0 / (double)30));
  return res - (20.0 * e1) - e2;
}


x86 assembly (clang, -O0):
<ackley>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  0xeb4(%rip),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xe9c(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1e,-0x2c(%rbp)
jge    11fc <ackley+0xbc>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    $0x1e,%esi
movzwl (%rax,%rcx,2),%edi
call   1060 <translate@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe53(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <cos@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118c <ackley+0x4c>
movsd  0xe04(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xe0f(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xde1(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xdec(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xdd0(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xda8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ackley>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movzwl (%r14,%rbx,2),%edi
mov    $0x1e,%esi
call   1060 <translate@plt>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
mulsd  0xe6b(%rip),%xmm0
call   1040 <cos@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rbx
cmp    $0x1e,%rbx
jne    1160 <ackley+0x20>
divsd  0xe4a(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
divsd  0xe2d(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11eb <ackley+0xab>
sqrtsd %xmm0,%xmm0
jmp    11f0 <ackley+0xb0>
call   1050 <sqrt@plt>
mulsd  0xe18(%rip),%xmm0
call   1030 <exp@plt>
mulsd  0xe13(%rip),%xmm0
addsd  0xe13(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define double @ackley([30 x i16]* nocapture %0) {
br label %11
2: ; preds = %11
%3 = fdiv double %22, 3.000000e+01
%4 = tail call double @exp(double %3)
%5 = fdiv double %18, 3.000000e+01
%6 = tail call double @sqrt(double %5)
%7 = fmul double %6, -2.000000e-01
%8 = tail call double @exp(double %7)
%9 = tail call double @llvm.fmuladd.f64(double %8, double -2.000000e+01, double 0x4036B7E151628AED)
%10 = fsub double %9, %4
ret double %10
11: ; preds = %1, %11
%12 = phi i64 [ 0, %1 ], [ %23, %11 ]
%13 = phi double [ 0.000000e+00, %1 ], [ %22, %11 ]
%14 = phi double [ 0.000000e+00, %1 ], [ %18, %11 ]
%15 = getelementptr inbounds [30 x i16], [30 x i16]* %0, i64 0, i64 %12
%16 = load i16, i16* %15
%17 = tail call double @translate(i16 zeroext %16, i32 30)
%18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %14)
%19 = fmul double %17, 0x401921FB82C2BD7F
%20 = tail call i64 @cos(double %19)
%21 = sitofp i64 %20 to double
%22 = fadd double %13, %21
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, 30
br i1 %24, label %2, label %11
}