#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(int, int);
double rosenbrock(double sol[], int DIM) {
  int i;
  double top = 0.00;
  for (i = 0; i < DIM - 1; i++) {
    top = top + 100. * pow((sol[i + 1] - pow(sol[i], 2.)), 2) +
          pow((1. - sol[i]), 2);
  }
  return top;
}


x86 assembly (clang, -O0):
<rosenbrock>:
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
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ed <rosenbrock+0xdd>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cvttsd2si (%rax,%rcx,8),%edi
mov    $0x2,%esi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
movsd  -0x28(%rbp),%xmm1
movsd  0xe6a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  0xe45(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <rosenbrock+0x1e>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rosenbrock>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm0,%xmm0
cmp    $0x2,%esi
jl     11bd <rosenbrock+0xad>
mov    %esi,%r14d
mov    %rdi,%r15
add    $0xffffffff,%r14d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%r12
movsd  0x8(%r15,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
cvttsd2si (%r15,%rbx,8),%edi
mov    $0x2,%esi
call   1030 <pow@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
mulsd  0xe79(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe6d(%rip),%xmm0
subsd  (%r15,%rbx,8),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
addsd  0x8(%rsp),%xmm0
mov    %r12,%rbx
cmp    %r12,%r14
jne    1140 <rosenbrock+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @rosenbrock(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 = %40, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %43
12: ; preds = %7
%13 = load double, double* %6
%14 = load double*, double** %3
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %14, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fptosi double %24 to i32
%26 = call double @pow(i32 %25, i32 2)
%27 = fsub double %19, %26
%28 = fptosi double %27 to i32
%29 = call double @pow(i32 %28, i32 2)
%30 = call double @llvm.fmuladd.f64(double 1.000000e+02, double %29, double %13)
%31 = load double*, double** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = fsub double 1.000000e+00, %35
%37 = fptosi double %36 to i32
%38 = call double @pow(i32 %37, i32 2)
%39 = fadd double %30, %38
store double %39, double* %6
br label %40
40: ; preds = %12
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %7
43: ; preds = %7
%44 = load double, double* %6
ret double %44
}

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