#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 f_griewank_rosenbrock_raw(const double *x,
                                 const size_t number_of_variables) {
  size_t i = 0;
  double tmp = 0;
  double result;
  result = 0.0;
  for (i = 0; i < number_of_variables - 1; ++i) {
    const double c1 = x[i] * x[i] - x[i + 1];
    const double c2 = 1.0 - x[i];
    tmp = 100.0 * c1 * c1 + c2 * c2;
    result += tmp / 4000. - cos(tmp);
  }
  result = 10. + 10. * result / (double)(number_of_variables - 1);
  return result;
}


x86 assembly (clang, -O0):
<f_griewank_rosenbrock_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    122b <f_griewank_rosenbrock_raw+0x11b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  0xe67(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe4d(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <f_griewank_rosenbrock_raw+0x30>
movsd  -0x28(%rbp),%xmm1
movsd  0xdc8(%rip),%xmm0
mulsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
movq   %rax,%xmm0
movaps 0xdd0(%rip),%xmm2
punpckldq %xmm2,%xmm0
movapd 0xdd4(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xd89(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_griewank_rosenbrock_raw>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
add    $0xffffffffffffffff,%r15
je     11bd <f_griewank_rosenbrock_raw+0xad>
mov    %rsi,%r14
mov    %rdi,%r12
xorpd  %xmm2,%xmm2
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm2,0x10(%rsp)
movsd  -0x8(%r12,%rbx,8),%xmm0
movsd  0xeab(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
subsd  (%r12,%rbx,8),%xmm2
movapd %xmm2,%xmm0
mulsd  0xe95(%rip),%xmm0
mulsd  %xmm1,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
divsd  0xe85(%rip),%xmm1
movsd  %xmm1,0x8(%rsp)
call   1030 <cos@plt>
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <f_griewank_rosenbrock_raw+0x30>
mulsd  0xe5d(%rip),%xmm2
jmp    11c1 <f_griewank_rosenbrock_raw+0xb1>
xorpd  %xmm2,%xmm2
movq   %r15,%xmm0
punpckldq 0xe52(%rip),%xmm0
subpd  0xe5a(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
addsd  0xe2a(%rip),%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @f_griewank_rosenbrock_raw(double* %0, i64 %1) {
%3 = alloca double*
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %3
store i64 %1, i64* %4
store i64 0, i64* %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store i64 0, i64* %5
br label %10
10: ; preds = %50, %2
%11 = load i64, i64* %5
%12 = load i64, i64* %4
%13 = sub i64 %12, 1
%14 = icmp ult i64 %11, %13
br i1 %14, label %15, label %53
15: ; preds = %10
%16 = load double*, double** %3
%17 = load i64, i64* %5
%18 = getelementptr inbounds double, double* %16, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %3
%21 = load i64, i64* %5
%22 = getelementptr inbounds double, double* %20, i64 %21
%23 = load double, double* %22
%24 = load double*, double** %3
%25 = load i64, i64* %5
%26 = add i64 %25, 1
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %19, double %23, double %29)
store double %30, double* %8
%31 = load double*, double** %3
%32 = load i64, i64* %5
%33 = getelementptr inbounds double, double* %31, i64 %32
%34 = load double, double* %33
%35 = fsub double 1.000000e+00, %34
store double %35, double* %9
%36 = load double, double* %8
%37 = fmul double 1.000000e+02, %36
%38 = load double, double* %8
%39 = load double, double* %9
%40 = load double, double* %9
%41 = fmul double %39, %40
%42 = call double @llvm.fmuladd.f64(double %37, double %38, double %41)
store double %42, double* %6
%43 = load double, double* %6
%44 = fdiv double %43, 4.000000e+03
%45 = load double, double* %6
%46 = call double @cos(double %45)
%47 = fsub double %44, %46
%48 = load double, double* %7
%49 = fadd double %48, %47
store double %49, double* %7
br label %50
50: ; preds = %15
%51 = load i64, i64* %5
%52 = add i64 %51, 1
store i64 %52, i64* %5
br label %10
53: ; preds = %10
%54 = load double, double* %7
%55 = fmul double 1.000000e+01, %54
%56 = load i64, i64* %4
%57 = sub i64 %56, 1
%58 = uitofp i64 %57 to double
%59 = fdiv double %55, %58
%60 = fadd double 1.000000e+01, %59
store double %60, double* %7
%61 = load double, double* %7
ret double %61
}

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