#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 **allocateDoubleMatrix(int, int);
double chiProbability(double **, int, int);
double chiSquaredDistribution(int, int);
int /*<<< orphan*/ printf(char *, ...);
void testChiSquared() {
  printf("\nChi Squared test\n");
  printf("chisq: the result is significant at p <%4.3f\n",
         chiSquaredDistribution(16, 3));
  double **observed, **observed2;
  observed = allocateDoubleMatrix(3, 3);
  observed[0][0] = 49;
  observed[0][1] = 50;
  observed[0][2] = 69;
  observed[1][0] = 24;
  observed[1][1] = 36;
  observed[1][2] = 38;
  observed[2][0] = 19;
  observed[2][1] = 22;
  observed[2][2] = 28;
  printf("chisq: the result is significant at p <%4.3f\n",
         chiProbability(observed, 3, 3));
  observed2 = allocateDoubleMatrix(2, 2);
  observed2[0][0] = 25;
  observed2[0][1] = 6;
  observed2[1][0] = 8;
  observed2[1][1] = 15;
  printf("chisq: the result is significant at p <%4.3f\n",
         chiProbability(observed2, 2, 2));
}


x86 assembly (clang, -O0):
<testChiSquared>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x10,%edi
mov    $0x3,%esi
call   1040 <chiSquaredDistribution@plt>
lea    0xf0f(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x3,%esi
mov    %esi,%edi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsd  0xece(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsd  0xeb3(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsd  0xe97(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xe7a(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xe5e(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xe41(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movsd  0xe24(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movsd  0xe08(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movsd  0xdeb(%rip),%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x3,%edx
mov    %edx,%esi
call   1050 <chiProbability@plt>
lea    0xe2a(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0x2,%esi
mov    %esi,%edi
call   1030 <allocateDoubleMatrix@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0xda1(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsd  0xd86(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xd69(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsd  0xd4d(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1050 <chiProbability@plt>
lea    0xdac(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testChiSquared>:
push   %rbx
lea    0xf26(%rip),%rdi
call   1060 <puts@plt>
mov    $0x10,%edi
mov    $0x3,%esi
call   1040 <chiSquaredDistribution@plt>
lea    0xedd(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    $0x3,%edi
mov    $0x3,%esi
call   1030 <allocateDoubleMatrix@plt>
mov    (%rax),%rcx
movaps 0xe6a(%rip),%xmm0
movups %xmm0,(%rcx)
movabs $0x4051400000000000,%rdx
40 51 40
mov    %rdx,0x10(%rcx)
mov    0x8(%rax),%rcx
movaps 0xe5e(%rip),%xmm0
movups %xmm0,(%rcx)
movabs $0x4043000000000000,%rdx
mov    %rdx,0x10(%rcx)
mov    0x10(%rax),%rcx
movaps 0xe52(%rip),%xmm0
movups %xmm0,(%rcx)
movabs $0x403c000000000000,%rdx
mov    %rdx,0x10(%rcx)
mov    %rax,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
call   1050 <chiProbability@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <allocateDoubleMatrix@plt>
mov    (%rax),%rcx
movaps 0xe1c(%rip),%xmm0
movups %xmm0,(%rcx)
mov    0x8(%rax),%rcx
movaps 0xe1e(%rip),%xmm0
movups %xmm0,(%rcx)
mov    %rax,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1050 <chiProbability@plt>
mov    %rbx,%rdi
mov    $0x1,%al
pop    %rbx
jmp    1070 <printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"\0AChi Squared test\0A\00"
@.str.1 = [46 x i8] c"chisq: the result is significant at p <%4.3f\0A\00"
define void @testChiSquared() {
%1 = alloca double**
%2 = alloca double**
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = call double @chiSquaredDistribution(i32 16, i32 3)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %4)
%6 = call double** @allocateDoubleMatrix(i32 3, i32 3)
store double** %6, double*** %1
%7 = load double**, double*** %1
%8 = getelementptr inbounds double*, double** %7, i64 0
%9 = load double*, double** %8
%10 = getelementptr inbounds double, double* %9, i64 0
store double 4.900000e+01, double* %10
%11 = load double**, double*** %1
%12 = getelementptr inbounds double*, double** %11, i64 0
%13 = load double*, double** %12
%14 = getelementptr inbounds double, double* %13, i64 1
store double 5.000000e+01, double* %14
%15 = load double**, double*** %1
%16 = getelementptr inbounds double*, double** %15, i64 0
%17 = load double*, double** %16
%18 = getelementptr inbounds double, double* %17, i64 2
store double 6.900000e+01, double* %18
%19 = load double**, double*** %1
%20 = getelementptr inbounds double*, double** %19, i64 1
%21 = load double*, double** %20
%22 = getelementptr inbounds double, double* %21, i64 0
store double 2.400000e+01, double* %22
%23 = load double**, double*** %1
%24 = getelementptr inbounds double*, double** %23, i64 1
%25 = load double*, double** %24
%26 = getelementptr inbounds double, double* %25, i64 1
store double 3.600000e+01, double* %26
%27 = load double**, double*** %1
%28 = getelementptr inbounds double*, double** %27, i64 1
%29 = load double*, double** %28
%30 = getelementptr inbounds double, double* %29, i64 2
store double 3.800000e+01, double* %30
%31 = load double**, double*** %1
%32 = getelementptr inbounds double*, double** %31, i64 2
%33 = load double*, double** %32
%34 = getelementptr inbounds double, double* %33, i64 0
store double 1.900000e+01, double* %34
%35 = load double**, double*** %1
%36 = getelementptr inbounds double*, double** %35, i64 2
%37 = load double*, double** %36
%38 = getelementptr inbounds double, double* %37, i64 1
store double 2.200000e+01, double* %38
%39 = load double**, double*** %1
%40 = getelementptr inbounds double*, double** %39, i64 2
%41 = load double*, double** %40
%42 = getelementptr inbounds double, double* %41, i64 2
store double 2.800000e+01, double* %42
%43 = load double**, double*** %1
%44 = call double @chiProbability(double** %43, i32 3, i32 3)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %44)
%46 = call double** @allocateDoubleMatrix(i32 2, i32 2)
store double** %46, double*** %2
%47 = load double**, double*** %2
%48 = getelementptr inbounds double*, double** %47, i64 0
%49 = load double*, double** %48
%50 = getelementptr inbounds double, double* %49, i64 0
store double 2.500000e+01, double* %50
%51 = load double**, double*** %2
%52 = getelementptr inbounds double*, double** %51, i64 0
%53 = load double*, double** %52
%54 = getelementptr inbounds double, double* %53, i64 1
store double 6.000000e+00, double* %54
%55 = load double**, double*** %2
%56 = getelementptr inbounds double*, double** %55, i64 1
%57 = load double*, double** %56
%58 = getelementptr inbounds double, double* %57, i64 0
store double 8.000000e+00, double* %58
%59 = load double**, double*** %2
%60 = getelementptr inbounds double*, double** %59, i64 1
%61 = load double*, double** %60
%62 = getelementptr inbounds double, double* %61, i64 1
store double 1.500000e+01, double* %62
%63 = load double**, double*** %2
%64 = call double @chiProbability(double** %63, i32 2, i32 2)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %64)
ret void
}

LLVM IR (-O2):
@.str.1 = [46 x i8] c"chisq: the result is significant at p <%4.3f\0A\00"
@str = [18 x i8] c"\0AChi Squared test\00"
define void @testChiSquared() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%2 = tail call double @chiSquaredDistribution(i32 16, i32 3)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %2)
%4 = tail call double** @allocateDoubleMatrix(i32 3, i32 3)
%5 = load double*, double** %4
%6 = bitcast double* %5 to <2 x double>*
store <2 x double> <double 4.900000e+01, double 5.000000e+01>, <2 x double>* %6
%7 = getelementptr inbounds double, double* %5, i64 2
store double 6.900000e+01, double* %7
%8 = getelementptr inbounds double*, double** %4, i64 1
%9 = load double*, double** %8
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 2.400000e+01, double 3.600000e+01>, <2 x double>* %10
%11 = getelementptr inbounds double, double* %9, i64 2
store double 3.800000e+01, double* %11
%12 = getelementptr inbounds double*, double** %4, i64 2
%13 = load double*, double** %12
%14 = bitcast double* %13 to <2 x double>*
store <2 x double> <double 1.900000e+01, double 2.200000e+01>, <2 x double>* %14
%15 = getelementptr inbounds double, double* %13, i64 2
store double 2.800000e+01, double* %15
%16 = tail call double @chiProbability(double** %4, i32 3, i32 3)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %16)
%18 = tail call double** @allocateDoubleMatrix(i32 2, i32 2)
%19 = bitcast double** %18 to <2 x double>**
%20 = load <2 x double>*, <2 x double>** %19
store <2 x double> <double 2.500000e+01, double 6.000000e+00>, <2 x double>* %20
%21 = getelementptr inbounds double*, double** %18, i64 1
%22 = bitcast double** %21 to <2 x double>**
%23 = load <2 x double>*, <2 x double>** %22
store <2 x double> <double 8.000000e+00, double 1.500000e+01>, <2 x double>* %23
%24 = tail call double @chiProbability(double** %18, i32 2, i32 2)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), double %24)
ret void
}