#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 pow(double, double);
double sin(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(double);
double schaffer_f6(double sol[], int DIM) {
  double top = 0;
  double top1 = 0;
  double top2 = 0;
  int j;
  for (j = 0; j < DIM - 1; j++) {
    top1 = pow(sin(sqrt(pow(sol[j], (double)2) + pow(sol[j + 1], (double)2))),
               (double)2) -
           0.5;
    top2 =
        pow(1.0 + 0.001 * (pow(sol[j], (double)2) + pow(sol[j + 1], (double)2)),
            (double)2);
    top = top + (0.5 + top1 / top2);
  }
  return top;
}


x86 assembly (clang, -O0):
<schaffer_f6>:
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,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1289 <schaffer_f6+0x159>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe84(%rip),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe60(%rip),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
mov    %eax,%edi
call   1030 <sin@plt>
movsd  0xe3b(%rip),%xmm1
call   1040 <pow@plt>
movsd  0xe26(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe10(%rip),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xdec(%rip),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xddb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdd7(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdbb(%rip),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
divsd  -0x28(%rbp),%xmm2
movsd  0xd92(%rip),%xmm1
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115e <schaffer_f6+0x2e>
movsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<schaffer_f6>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xorps  %xmm0,%xmm0
cmp    $0x2,%esi
jl     11e1 <schaffer_f6+0xc1>
mov    %esi,%r14d
mov    %rdi,%r15
add    $0xffffffff,%r14d
movsd  (%rdi),%xmm1
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mulsd  %xmm1,%xmm1
lea    0x1(%rbx),%r12
movsd  0x8(%r15,%rbx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1030 <sin@plt>
movupd (%r15,%rbx,8),%xmm1
mulsd  %xmm0,%xmm0
movapd %xmm1,%xmm2
mulpd  %xmm1,%xmm2
movapd %xmm2,%xmm3
unpckhpd %xmm2,%xmm3
addsd  %xmm2,%xmm3
addsd  0xe62(%rip),%xmm0
mulsd  0xe62(%rip),%xmm3
addsd  0xe62(%rip),%xmm3
mulsd  %xmm3,%xmm3
divsd  %xmm3,%xmm0
addsd  0xe5a(%rip),%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movsd  (%rsp),%xmm0
unpckhpd %xmm1,%xmm1
mov    %r12,%rbx
cmp    %r12,%r14
jne    1150 <schaffer_f6+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @schaffer_f6(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %55, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %58
14: ; preds = %9
%15 = load double*, double** %3
%16 = load i32, i32* %8
%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 = load double*, double** %3
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %21, i64 %24
%26 = load double, double* %25
%27 = call double @pow(double %26, double 2.000000e+00)
%28 = fadd double %20, %27
%29 = call i32 @sqrt(double %28)
%30 = call double @sin(i32 %29)
%31 = call double @pow(double %30, double 2.000000e+00)
%32 = fsub double %31, 5.000000e-01
store double %32, double* %6
%33 = load double*, double** %3
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = call double @pow(double %37, double 2.000000e+00)
%39 = load double*, double** %3
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %39, i64 %42
%44 = load double, double* %43
%45 = call double @pow(double %44, double 2.000000e+00)
%46 = fadd double %38, %45
%47 = call double @llvm.fmuladd.f64(double 1.000000e-03, double %46, double 1.000000e+00)
%48 = call double @pow(double %47, double 2.000000e+00)
store double %48, double* %7
%49 = load double, double* %5
%50 = load double, double* %6
%51 = load double, double* %7
%52 = fdiv double %50, %51
%53 = fadd double 5.000000e-01, %52
%54 = fadd double %49, %53
store double %54, double* %5
br label %55
55: ; preds = %14
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %9
58: ; preds = %9
%59 = load double, double* %5
ret double %59
}

LLVM IR (-O2):
define double @schaffer_f6(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %36
4: ; preds = %2
%5 = add nsw i32 %1, -1
%6 = zext i32 %5 to i64
%7 = load double, double* %0
br label %8
8: ; preds = %4, %8
%9 = phi double [ %7, %4 ], [ %35, %8 ]
%10 = phi i64 [ 0, %4 ], [ %14, %8 ]
%11 = phi double [ 0.000000e+00, %4 ], [ %33, %8 ]
%12 = getelementptr inbounds double, double* %0, i64 %10
%13 = fmul double %9, %9
%14 = add nuw nsw i64 %10, 1
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = fmul double %16, %16
%18 = fadd double %13, %17
%19 = tail call i32 @sqrt(double %18)
%20 = tail call double @sin(i32 %19)
%21 = fmul double %20, %20
%22 = fadd double %21, -5.000000e-01
%23 = bitcast double* %12 to <2 x double>*
%24 = load <2 x double>, <2 x double>* %23
%25 = fmul <2 x double> %24, %24
%26 = shufflevector <2 x double> %25, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%27 = fadd <2 x double> %25, %26
%28 = extractelement <2 x double> %27, i64 0
%29 = tail call double @llvm.fmuladd.f64(double %28, double 1.000000e-03, double 1.000000e+00)
%30 = fmul double %29, %29
%31 = fdiv double %22, %30
%32 = fadd double %31, 5.000000e-01
%33 = fadd double %11, %32
%34 = icmp eq i64 %14, %6
%35 = extractelement <2 x double> %24, i64 1
br i1 %34, label %36, label %8
36: ; preds = %8, %2
%37 = phi double [ 0.000000e+00, %2 ], [ %33, %8 ]
ret double %37
}