#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__ pow(double, int);
float merit_function_golden(double *a, float *x, float *y, int n,
                            double (*f)(float, float)) {
  float e = 0.0;
  int i;
  for (i = 0; i < n; i++)
    e += pow(y[i] - f(*a, x[i]), 2);
  return e;
}


x86 assembly (clang, -O0):
<merit_function_golden>:
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    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ae <merit_function_golden+0x9e>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movsd  (%rcx),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rcx
movslq -0x30(%rbp),%rdx
movss  (%rcx,%rdx,4),%xmm1
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2ss %rax,%xmm0
addss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    113a <merit_function_golden+0x2a>
movss  -0x2c(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merit_function_golden>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %ecx,%ecx
jle    11aa <merit_function_golden+0x9a>
mov    %r8,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %ecx,%ebx
xorps  %xmm0,%xmm0
xor    %ebp,%ebp
nopl   0x0(%rax)
movss  %xmm0,0xc(%rsp)
movss  (%r15,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x0(%r13),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  (%r12,%rbp,4),%xmm1
call   *%r14
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
movss  0xc(%rsp),%xmm0
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <merit_function_golden+0x30>
jmp    11ad <merit_function_golden+0x9d>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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