void chsone(double bins[], double ebins[], int nbins, int knstrn, double *df,
            double *chsq, double *prob) {
  double gammq(double a, double x);
  void nrerror(char error_text[]);
  int j;
  double temp;
  *df = nbins - knstrn;
  *chsq = 0.0;
  for (j = 1; j <= nbins; j++) {
    if (ebins[j] <= 0.0)
      nrerror("Bad expected number in chsone");
    temp = bins[j] - ebins[j];
    *chsq += temp * temp / ebins[j];
  }
  *prob = gammq(0.5 * (*df), 0.5 * (*chsq));
}


x86 assembly (clang, -O0):
<chsone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11e4 <chsone+0xc4>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jb     1194 <chsone+0x74>
lea    0xe79(%rip),%rdi
call   1040 <nrerror@plt>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1166 <chsone+0x46>
mov    -0x20(%rbp),%rax
movsd  0xe10(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
movsd  0xe00(%rip),%xmm1
mulsd  (%rax),%xmm1
call   1030 <gammq@plt>
mov    0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chsone>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
mov    0x40(%rsp),%rbp
movsd  %xmm0,(%r8)
movq   $0x0,(%r9)
test   %edx,%edx
jle    11e3 <chsone+0xc3>
mov    %r9,%r12
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %r8,(%rsp)
add    $0x1,%r15d
mov    $0x1,%r14d
xorpd  %xmm3,%xmm3
lea    0xe97(%rip),%rbp
xorpd  %xmm1,%xmm1
jmp    11aa <chsone+0x8a>
nopw   0x0(%rax,%rax,1)
movapd %xmm1,%xmm2
movsd  0x0(%r13,%r14,8),%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,(%r12)
add    $0x1,%r14
cmp    %r14,%r15
je     11d0 <chsone+0xb0>
movsd  (%rbx,%r14,8),%xmm0
ucomisd %xmm0,%xmm3
jb     1180 <chsone+0x60>
mov    %rbp,%rdi
call   1040 <nrerror@plt>
xorpd  %xmm3,%xmm3
movsd  (%rbx,%r14,8),%xmm0
movsd  (%r12),%xmm1
jmp    1180 <chsone+0x60>
mulsd  0xe28(%rip),%xmm1
mov    0x40(%rsp),%rbp
mov    (%rsp),%r8
jmp    11e7 <chsone+0xc7>
xorpd  %xmm1,%xmm1
movsd  (%r8),%xmm0
mulsd  0xe0c(%rip),%xmm0
call   1030 <gammq@plt>
movsd  %xmm0,0x0(%rbp)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Bad expected number in chsone\00"
define void @chsone(double* %0, double* %1, i32 %2, i32 %3, double* %4, double* %5, double* %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca double
store double* %0, double** %8
store double* %1, double** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store double* %4, double** %12
store double* %5, double** %13
store double* %6, double** %14
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = sub nsw i32 %17, %18
%20 = sitofp i32 %19 to double
%21 = load double*, double** %12
store double %20, double* %21
%22 = load double*, double** %13
store double 0.000000e+00, double* %22
store i32 1, i32* %15
br label %23
23: ; preds = %59, %7
%24 = load i32, i32* %15
%25 = load i32, i32* %10
%26 = icmp sle i32 %24, %25
br i1 %26, label %27, label %62
27: ; preds = %23
%28 = load double*, double** %9
%29 = load i32, i32* %15
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fcmp ole double %32, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %27
br label %35
35: ; preds = %34, %27
%36 = load double*, double** %8
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double*, double** %9
%42 = load i32, i32* %15
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = fsub double %40, %45
store double %46, double* %16
%47 = load double, double* %16
%48 = load double, double* %16
%49 = fmul double %47, %48
%50 = load double*, double** %9
%51 = load i32, i32* %15
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = fdiv double %49, %54
%56 = load double*, double** %13
%57 = load double, double* %56
%58 = fadd double %57, %55
store double %58, double* %56
br label %59
59: ; preds = %35
%60 = load i32, i32* %15
%61 = add nsw i32 %60, 1
store i32 %61, i32* %15
br label %23
62: ; preds = %23
%63 = load double*, double** %12
%64 = load double, double* %63
%65 = fmul double 5.000000e-01, %64
%66 = load double*, double** %13
%67 = load double, double* %66
%68 = fmul double 5.000000e-01, %67
%69 = call double @gammq(double %65, double %68)
%70 = load double*, double** %14
store double %69, double* %70
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Bad expected number in chsone\00"
define void @chsone(double* nocapture %0, double* nocapture %1, i32 %2, i32 %3, double* nocapture %4, double* nocapture %5, double* nocapture writeonly %6) {
%8 = sub nsw i32 %2, %3
%9 = sitofp i32 %8 to double
store double %9, double* %4
store double 0.000000e+00, double* %5
%10 = icmp slt i32 %2, 1
br i1 %10, label %36, label %11
11: ; preds = %7
%12 = add nuw i32 %2, 1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %11, %23
%15 = phi double [ 0.000000e+00, %11 ], [ %31, %23 ]
%16 = phi i64 [ 1, %11 ], [ %32, %23 ]
%17 = getelementptr inbounds double, double* %1, i64 %16
%18 = load double, double* %17
%19 = fcmp ugt double %18, 0.000000e+00
br i1 %19, label %23, label %20
20: ; preds = %14
tail call void @nrerror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%21 = load double, double* %17
%22 = load double, double* %5
br label %23
23: ; preds = %20, %14
%24 = phi double [ %22, %20 ], [ %15, %14 ]
%25 = phi double [ %21, %20 ], [ %18, %14 ]
%26 = getelementptr inbounds double, double* %0, i64 %16
%27 = load double, double* %26
%28 = fsub double %27, %25
%29 = fmul double %28, %28
%30 = fdiv double %29, %25
%31 = fadd double %24, %30
store double %31, double* %5
%32 = add nuw nsw i64 %16, 1
%33 = icmp eq i64 %32, %13
br i1 %33, label %34, label %14
34: ; preds = %23
%35 = fmul double %31, 5.000000e-01
br label %36
36: ; preds = %34, %7
%37 = phi double [ %35, %34 ], [ 0.000000e+00, %7 ]
%38 = load double, double* %4
%39 = fmul double %38, 5.000000e-01
%40 = tail call double @gammq(double %39, double %37)
store double %40, double* %6
ret void
}