#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 */
int pow(int, int);
double pso_rosenbrock(double *vec, int dim, void *params) {
  double sum = 0;
  int i;
  for (i = 0; i < dim - 1; i++)
    sum += 100 * pow((vec[i + 1] - pow(vec[i], 2)), 2) + pow((1 - vec[i]), 2);
  return sum;
}


x86 assembly (clang, -O0):
<pso_rosenbrock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d8 <pso_rosenbrock+0xc8>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
cvttsd2si (%rax,%rcx,8),%edi
mov    $0x2,%esi
call   1030 <pow@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
imul   $0x64,%eax,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe5e(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <pso_rosenbrock+0x22>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pso_rosenbrock>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
cmp    $0x2,%esi
jl     11cc <pso_rosenbrock+0xbc>
mov    %esi,%r14d
mov    %rdi,%r15
add    $0xffffffff,%r14d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
lea    0x1(%rbx),%r12
movsd  0x8(%r15,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
cvttsd2si (%r15,%rbx,8),%edi
mov    $0x2,%esi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
imul   $0x64,%eax,%ebp
movsd  0xe70(%rip),%xmm0
subsd  (%r15,%rbx,8),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
add    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
mov    %r12,%rbx
cmp    %r12,%r14
jne    1140 <pso_rosenbrock+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @pso_rosenbrock(double* %0, i32 %1, i8* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %45, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %48
14: ; preds = %9
%15 = load double*, double** %4
%16 = load i32, i32* %8
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %15, i64 %18
%20 = load double, double* %19
%21 = load double*, double** %4
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = fptosi double %25 to i32
%27 = call i32 @pow(i32 %26, i32 2)
%28 = sitofp i32 %27 to double
%29 = fsub double %20, %28
%30 = fptosi double %29 to i32
%31 = call i32 @pow(i32 %30, i32 2)
%32 = mul nsw i32 100, %31
%33 = load double*, double** %4
%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 = fsub double 1.000000e+00, %37
%39 = fptosi double %38 to i32
%40 = call i32 @pow(i32 %39, i32 2)
%41 = add nsw i32 %32, %40
%42 = sitofp i32 %41 to double
%43 = load double, double* %7
%44 = fadd double %43, %42
store double %44, double* %7
br label %45
45: ; preds = %14
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %9
48: ; preds = %9
%49 = load double, double* %7
ret double %49
}

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