double loss_rho(double *r, double scale, int n, int p, double rhoc) {
  double Chi(double x, double c);
  register int i;
  double s = 0;
  for (i = 0; i < n; i++)
    s += Chi(r[i] / scale, rhoc);
  return (s / (double)n);
}


x86 assembly (clang, -O0):
<loss_rho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117b <loss_rho+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <Chi@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113b <loss_rho+0x2b>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loss_rho>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
test   %esi,%esi
jle    1175 <loss_rho+0x65>
movapd %xmm0,%xmm3
mov    %rdi,%r15
mov    %r14d,%ebp
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
nopl   0x0(%rax)
movsd  %xmm2,0x10(%rsp)
movsd  (%r15,%rbx,8),%xmm0
divsd  %xmm3,%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <Chi@plt>
movsd  (%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <loss_rho+0x30>
jmp    1179 <loss_rho+0x69>
xorpd  %xmm2,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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