#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 */
double fabs(double);
double log10(double);
int /*<<< orphan*/ printf(char *, int, ...);
double chiSquareLogTest(int n_exp, double *experimental, double *theoretical,
                        double *sigma) {
  int i = 0;
  double chiSquare = 0.0;
  double delta = fabs(experimental[0] - log10(theoretical[0]));
  printf("Delta=%lf\n", delta);
  for (i = 0; i < n_exp; i++) {
    printf("%d\t%lf\t%lf\n", i, experimental[i],
           (log10(theoretical[i]) - delta));
    double diff =
        ((experimental[i] - log10(theoretical[i]) - delta) / sigma[i]);
    chiSquare += (diff * diff);
  }
  chiSquare = (chiSquare / (double)n_exp);
  return chiSquare;
}


x86 assembly (clang, -O0):
<chiSquareLogTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1040 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movaps 0xe8d(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    125b <chiSquareLogTest+0x13b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <log10@plt>
mov    -0x5c(%rbp),%esi
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm1
lea    0xe38(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <chiSquareLogTest+0x76>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chiSquareLogTest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  (%rsi),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  (%rdx),%xmm0
call   1040 <log10@plt>
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xea3(%rip),%xmm1
movapd %xmm1,0x10(%rsp)
cvttsd2si %xmm1,%esi
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
mov    %ebp,0xc(%rsp)
jle    1219 <chiSquareLogTest+0xf9>
mov    %ebp,%r14d
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
lea    0xe8a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x20(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,(%rsp)
movsd  (%r12,%rbp,8),%xmm0
call   1040 <log10@plt>
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
mov    %r13,%rdi
mov    %ebp,%esi
movsd  (%rsp),%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
movsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,(%rsp)
movsd  (%r12,%rbp,8),%xmm0
call   1040 <log10@plt>
movsd  0x20(%rsp),%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm0,%xmm2
subsd  0x10(%rsp),%xmm2
divsd  (%r15,%rbp,8),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm2,%xmm1
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11a0 <chiSquareLogTest+0x80>
jmp    121d <chiSquareLogTest+0xfd>
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Delta=%lf\0A\00"
@.str.1 = [12 x i8] c"%d\09%lf\09%lf\0A\00"
define double @chiSquareLogTest(i32 %0, double* %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
store i32 0, i32* %9
store double 0.000000e+00, double* %10
%13 = load double*, double** %6
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = load double*, double** %7
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = call double @log10(double %18)
%20 = fsub double %15, %19
%21 = call double @llvm.fabs.f64(double %20)
store double %21, double* %11
%22 = load double, double* %11
%23 = fptosi double %22 to i32
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 0, i32* %9
br label %25
25: ; preds = %69, %4
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %72
29: ; preds = %25
%30 = load i32, i32* %9
%31 = load double*, double** %6
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %7
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = call double @log10(double %40)
%42 = load double, double* %11
%43 = fsub double %41, %42
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %30, double %35, double %43)
%45 = load double*, double** %6
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double*, double** %7
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = call double @log10(double %54)
%56 = fsub double %49, %55
%57 = load double, double* %11
%58 = fsub double %56, %57
%59 = load double*, double** %8
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = fdiv double %58, %63
store double %64, double* %12
%65 = load double, double* %12
%66 = load double, double* %12
%67 = load double, double* %10
%68 = call double @llvm.fmuladd.f64(double %65, double %66, double %67)
store double %68, double* %10
br label %69
69: ; preds = %29
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %25
72: ; preds = %25
%73 = load double, double* %10
%74 = load i32, i32* %5
%75 = sitofp i32 %74 to double
%76 = fdiv double %73, %75
store double %76, double* %10
%77 = load double, double* %10
ret double %77
}

LLVM IR (-O2):
@.str = [11 x i8] c"Delta=%lf\0A\00"
@.str.1 = [12 x i8] c"%d\09%lf\09%lf\0A\00"
define double @chiSquareLogTest(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
%5 = load double, double* %1
%6 = load double, double* %2
%7 = tail call double @log10(double %6)
%8 = fsub double %5, %7
%9 = tail call double @llvm.fabs.f64(double %8)
%10 = fptosi double %9 to i32
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %37
13: ; preds = %4
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %35, %15 ]
%17 = phi double [ 0.000000e+00, %13 ], [ %34, %15 ]
%18 = getelementptr inbounds double, double* %1, i64 %16
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %2, i64 %16
%21 = load double, double* %20
%22 = tail call double @log10(double %21)
%23 = fsub double %22, %9
%24 = trunc i64 %16 to i32
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %24, double %19, double %23)
%26 = load double, double* %18
%27 = load double, double* %20
%28 = tail call double @log10(double %27)
%29 = fsub double %26, %28
%30 = fsub double %29, %9
%31 = getelementptr inbounds double, double* %3, i64 %16
%32 = load double, double* %31
%33 = fdiv double %30, %32
%34 = tail call double @llvm.fmuladd.f64(double %33, double %33, double %17)
%35 = add nuw nsw i64 %16, 1
%36 = icmp eq i64 %35, %14
br i1 %36, label %37, label %15
37: ; preds = %15, %4
%38 = phi double [ 0.000000e+00, %4 ], [ %34, %15 ]
%39 = sitofp i32 %0 to double
%40 = fdiv double %38, %39
ret double %40
}