#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
double chisquare(long *actual, double *probability, long n, long k, int *nb) {
  double V, prob;
  long i, n_actual, nbins;
  int ch;
  V = 0.0;
  for (i = n_actual = nbins = 0, prob = 0.0; i < k; i++) {
    n_actual += actual[i];
    prob += probability[i];
    if (n * prob >= 5 || i == k - 1) {
      V += (n_actual - n * prob) * (n_actual - n * prob) / (n * prob);
      nbins++;
      n_actual = 0;
      prob = 0.0;
    }
  }
  *nb = nbins;
  if (nbins == 1)
    fprintf(stderr, "WARNING: Only one bin was used in Chisquare\n");
  else if (nbins == 0)
    fprintf(stderr, "WARNING: No bin was used in Chisquare => n was <= 5.\n");
  else if (nbins != k)
    fprintf(stderr,
            "WARNING: The effective number of bins in Chisquare: %ld, was less "
            "than the given number of bins: %ld, due to the effect of "
            "combining bins in order to make the expected number of hits per "
            "bin sufficiently large.\n",
            nbins, k);
  return V;
}


x86 assembly (clang, -O0):
<chisquare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    126e <chisquare+0x15e>
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  0xe60(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    11bf <chisquare+0xaf>
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    1258 <chisquare+0x148>
cvtsi2sdq -0x48(%rbp),%xmm1
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdq -0x48(%rbp),%xmm2
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm3
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    125d <chisquare+0x14d>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1154 <chisquare+0x44>
mov    -0x50(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x1,-0x50(%rbp)
jne    12a1 <chisquare+0x191>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12ff <chisquare+0x1ef>
cmpq   $0x0,-0x50(%rbp)
jne    12c8 <chisquare+0x1b8>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12fa <chisquare+0x1ea>
mov    -0x50(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     12f5 <chisquare+0x1e5>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12fa <chisquare+0x1ea>
jmp    12ff <chisquare+0x1ef>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chisquare>:
push   %rax
test   %rcx,%rcx
jle    11c5 <chisquare+0xb5>
cvtsi2sd %rdx,%xmm6
movapd 0xed9(%rip),%xmm1
xorpd  %xmm6,%xmm1
lea    -0x1(%rcx),%r9
xorpd  %xmm0,%xmm0
xor    %edx,%edx
movsd  0xed3(%rip),%xmm2
xor    %r10d,%r10d
xor    %eax,%eax
xorpd  %xmm3,%xmm3
jmp    1180 <chisquare+0x70>
nopl   0x0(%rax,%rax,1)
xorps  %xmm5,%xmm5
cvtsi2sd %r10,%xmm5
mulsd  %xmm1,%xmm3
addsd  %xmm5,%xmm3
mulsd  %xmm3,%xmm3
divsd  %xmm4,%xmm3
addsd  %xmm3,%xmm0
add    $0x1,%rdx
xorpd  %xmm3,%xmm3
xor    %r10d,%r10d
add    $0x1,%rax
cmp    %rax,%rcx
je     119e <chisquare+0x8e>
addsd  (%rsi,%rax,8),%xmm3
movapd %xmm3,%xmm4
mulsd  %xmm6,%xmm4
add    (%rdi,%rax,8),%r10
ucomisd %xmm2,%xmm4
jae    1150 <chisquare+0x40>
cmp    %rax,%r9
jne    1177 <chisquare+0x67>
jmp    1150 <chisquare+0x40>
mov    %edx,(%r8)
test   %rdx,%rdx
je     11d0 <chisquare+0xc0>
cmp    $0x1,%rdx
jne    11f3 <chisquare+0xe3>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
movsd  %xmm0,(%rsp)
jmp    11e7 <chisquare+0xd7>
movl   $0x0,(%r8)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret
cmp    %rcx,%rdx
je     11f1 <chisquare+0xe1>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
xor    %eax,%eax
movsd  %xmm0,(%rsp)
call   1030 <fprintf@plt>
jmp    11ec <chisquare+0xdc>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"WARNING: Only one bin was used in Chisquare\0A\00"
@.str.1 = [54 x i8] c"WARNING: No bin was used in Chisquare => n was <= 5.\0A\00"
@.str.2 = [212 x i8] c"WARNING: The effective number of bins in Chisquare: %ld, was less than the given number of bins: %ld, due to the effect of combining bins in order to make the expected number of hits per bin sufficiently large.\0A\00"
define double @chisquare(i64* %0, double* %1, i64 %2, i64 %3, i32* %4) {
%6 = alloca i64*
%7 = alloca double*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca double
%12 = alloca double
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
store i64* %0, i64** %6
store double* %1, double** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i32* %4, i32** %10
store double 0.000000e+00, double* %11
store i64 0, i64* %15
store i64 0, i64* %14
store i64 0, i64* %13
store double 0.000000e+00, double* %12
br label %17
17: ; preds = %70, %5
%18 = load i64, i64* %13
%19 = load i64, i64* %9
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %73
21: ; preds = %17
%22 = load i64*, i64** %6
%23 = load i64, i64* %13
%24 = getelementptr inbounds i64, i64* %22, i64 %23
%25 = load i64, i64* %24
%26 = load i64, i64* %14
%27 = add nsw i64 %26, %25
store i64 %27, i64* %14
%28 = load double*, double** %7
%29 = load i64, i64* %13
%30 = getelementptr inbounds double, double* %28, i64 %29
%31 = load double, double* %30
%32 = load double, double* %12
%33 = fadd double %32, %31
store double %33, double* %12
%34 = load i64, i64* %8
%35 = sitofp i64 %34 to double
%36 = load double, double* %12
%37 = fmul double %35, %36
%38 = fcmp oge double %37, 5.000000e+00
br i1 %38, label %44, label %39
39: ; preds = %21
%40 = load i64, i64* %13
%41 = load i64, i64* %9
%42 = sub nsw i64 %41, 1
%43 = icmp eq i64 %40, %42
br i1 %43, label %44, label %69
44: ; preds = %39, %21
%45 = load i64, i64* %14
%46 = sitofp i64 %45 to double
%47 = load i64, i64* %8
%48 = sitofp i64 %47 to double
%49 = load double, double* %12
%50 = fneg double %48
%51 = call double @llvm.fmuladd.f64(double %50, double %49, double %46)
%52 = load i64, i64* %14
%53 = sitofp i64 %52 to double
%54 = load i64, i64* %8
%55 = sitofp i64 %54 to double
%56 = load double, double* %12
%57 = fneg double %55
%58 = call double @llvm.fmuladd.f64(double %57, double %56, double %53)
%59 = fmul double %51, %58
%60 = load i64, i64* %8
%61 = sitofp i64 %60 to double
%62 = load double, double* %12
%63 = fmul double %61, %62
%64 = fdiv double %59, %63
%65 = load double, double* %11
%66 = fadd double %65, %64
store double %66, double* %11
%67 = load i64, i64* %15
%68 = add nsw i64 %67, 1
store i64 %68, i64* %15
store i64 0, i64* %14
store double 0.000000e+00, double* %12
br label %69
69: ; preds = %44, %39
br label %70
70: ; preds = %69
%71 = load i64, i64* %13
%72 = add nsw i64 %71, 1
store i64 %72, i64* %13
br label %17
73: ; preds = %17
%74 = load i64, i64* %15
%75 = trunc i64 %74 to i32
%76 = load i32*, i32** %10
store i32 %75, i32* %76
%77 = load i64, i64* %15
%78 = icmp eq i64 %77, 1
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %99
82: ; preds = %73
%83 = load i64, i64* %15
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
br label %98
88: ; preds = %82
%89 = load i64, i64* %15
%90 = load i64, i64* %9
%91 = icmp ne i64 %89, %90
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = load i64, i64* %15
%95 = load i64, i64* %9
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([212 x i8], [212 x i8]* @.str.2, i64 0, i64 0), i64 %94, i64 %95)
br label %97
97: ; preds = %92, %88
br label %98
98: ; preds = %97, %85
br label %99
99: ; preds = %98, %79
%100 = load double, double* %11
ret double %100
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"WARNING: Only one bin was used in Chisquare\0A\00"
@.str.1 = [54 x i8] c"WARNING: No bin was used in Chisquare => n was <= 5.\0A\00"
@.str.2 = [212 x i8] c"WARNING: The effective number of bins in Chisquare: %ld, was less than the given number of bins: %ld, due to the effect of combining bins in order to make the expected number of hits per bin sufficiently large.\0A\00"
define double @chisquare(i64* nocapture %0, double* nocapture %1, i64 %2, i64 %3, i32* nocapture writeonly %4) {
%6 = icmp sgt i64 %3, 0
br i1 %6, label %8, label %7
7: ; preds = %5
store i32 0, i32* %4
br label %47
8: ; preds = %5
%9 = sitofp i64 %2 to double
%10 = add nsw i64 %3, -1
%11 = fneg double %9
br label %12
12: ; preds = %8, %35
%13 = phi double [ 0.000000e+00, %8 ], [ %39, %35 ]
%14 = phi i64 [ 0, %8 ], [ %38, %35 ]
%15 = phi i64 [ 0, %8 ], [ %37, %35 ]
%16 = phi i64 [ 0, %8 ], [ %40, %35 ]
%17 = phi double [ 0.000000e+00, %8 ], [ %36, %35 ]
%18 = getelementptr inbounds i64, i64* %0, i64 %16
%19 = load i64, i64* %18
%20 = add nsw i64 %19, %15
%21 = getelementptr inbounds double, double* %1, i64 %16
%22 = load double, double* %21
%23 = fadd double %17, %22
%24 = fmul double %23, %9
%25 = fcmp oge double %24, 5.000000e+00
%26 = icmp eq i64 %16, %10
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %28, label %35
28: ; preds = %12
%29 = sitofp i64 %20 to double
%30 = tail call double @llvm.fmuladd.f64(double %11, double %23, double %29)
%31 = fmul double %30, %30
%32 = fdiv double %31, %24
%33 = fadd double %13, %32
%34 = add nsw i64 %14, 1
br label %35
35: ; preds = %12, %28
%36 = phi double [ 0.000000e+00, %28 ], [ %23, %12 ]
%37 = phi i64 [ 0, %28 ], [ %20, %12 ]
%38 = phi i64 [ %34, %28 ], [ %14, %12 ]
%39 = phi double [ %33, %28 ], [ %13, %12 ]
%40 = add nuw nsw i64 %16, 1
%41 = icmp eq i64 %40, %3
br i1 %41, label %42, label %12
42: ; preds = %35
%43 = trunc i64 %38 to i32
store i32 %43, i32* %4
switch i64 %38, label %51 [
i64 1, label %44
i64 0, label %47
]
44: ; preds = %42
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %56
47: ; preds = %7, %42
%48 = phi double [ 0.000000e+00, %7 ], [ %39, %42 ]
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
br label %56
51: ; preds = %42
%52 = icmp eq i64 %38, %3
br i1 %52, label %56, label %53
53: ; preds = %51
%54 = load i32, i32* @stderr
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([212 x i8], [212 x i8]* @.str.2, i64 0, i64 0), i64 %38, i64 %3)
br label %56
56: ; preds = %47, %53, %51, %44
%57 = phi double [ %48, %47 ], [ %39, %53 ], [ %39, %51 ], [ %39, %44 ]
ret double %57
}