#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__ model_function(double, double *);
scalar_t__ pow(scalar_t__, int);
double objective_function(double x[], double y[], double parameters[], int n,
                          int k) {
  double sum = 0;
  int i;
  for (i = 0; i < k; i++) {
    sum += (pow(y[i] - model_function(x[i], parameters), 2));
  }
  return sum;
}


x86 assembly (clang, -O0):
<objective_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b8 <objective_function+0x98>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <model_function@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
mov    $0x2,%esi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114a <objective_function+0x2a>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<objective_function>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %r8d,%r8d
jle    11b6 <objective_function+0x96>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %r8d,%r13d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r12,%rbx,8),%xmm0
mov    %r14,%rdi
call   1030 <model_function@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
mov    $0x2,%esi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <objective_function+0x30>
jmp    11b9 <objective_function+0x99>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @objective_function(double* %0, double* %1, double* %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %12
br label %13
13: ; preds = %37, %5
%14 = load i32, i32* %12
%15 = load i32, i32* %10
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = load double*, double** %7
%19 = load i32, i32* %12
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %6
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %8
%29 = call i64 @model_function(double %27, double* %28)
%30 = sitofp i64 %29 to double
%31 = fsub double %22, %30
%32 = fptosi double %31 to i64
%33 = call i64 @pow(i64 %32, i32 2)
%34 = sitofp i64 %33 to double
%35 = load double, double* %11
%36 = fadd double %35, %34
store double %36, double* %11
br label %37
37: ; preds = %17
%38 = load i32, i32* %12
%39 = add nsw i32 %38, 1
store i32 %39, i32* %12
br label %13
40: ; preds = %13
%41 = load double, double* %11
ret double %41
}

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