#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*/ printf(char *, ...);
int rnd();
void chi_square_test() {
  int i, j, rank, hist[11];
  double e = 0.0;
  for (i = 1; i <= 10; i++) {
    hist[i] = 0;
  }
  for (i = 1; i < 1000; i++) {
    rank = (int)(10 * rnd() + 1);
    hist[rank]++;
  }
  for (i = 1; i <= 10; i++) {
    printf("%3d:%3d ", i, hist[i]);
    for (j = 0; j < hist[i] * (40.0 / (1000 / 10)); j++) {
      printf("*");
    }
    printf("\n");
    e = e +
        (double)(hist[i] - (1000 / 10)) * (hist[i] - (1000 / 10)) / (1000 / 10);
  }
  printf("x 2 = %f\n", e);
}


x86 assembly (clang, -O0):
<chi_square_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jg     115b <chi_square_test+0x3b>
movslq -0x4(%rbp),%rax
movl   $0x0,-0x40(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1137 <chi_square_test+0x17>
movl   $0x1,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    119c <chi_square_test+0x7c>
mov    $0x0,%al
call   1040 <rnd@plt>
imul   $0xa,%eax,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1162 <chi_square_test+0x42>
movl   $0x1,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jg     1266 <chi_square_test+0x146>
mov    -0x4(%rbp),%esi
movslq -0x4(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movslq -0x4(%rbp),%rax
cvtsi2sdl -0x40(%rbp,%rax,4),%xmm0
movsd  0xe1c(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    120e <chi_square_test+0xee>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11cd <chi_square_test+0xad>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x48(%rbp),%xmm0
movslq -0x4(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
sub    $0x64,%eax
cvtsi2sd %eax,%xmm1
movslq -0x4(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
sub    $0x64,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdbd(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <chi_square_test+0x83>
movsd  -0x48(%rbp),%xmm0
lea    0xda9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chi_square_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
xorpd  %xmm0,%xmm0
movupd %xmm0,0x24(%rsp)
movupd %xmm0,0x14(%rsp)
movq   $0x0,0x34(%rsp)
mov    $0x3e7,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rnd@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
or     $0x1,%eax
cltq
addl   $0x1,0x10(%rsp,%rax,4)
add    $0xffffffff,%ebx
jne    1160 <chi_square_test+0x30>
mov    $0x1,%ebx
lea    0xe91(%rip),%r14
xorpd  %xmm0,%xmm0
jmp    11c9 <chi_square_test+0x99>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xffffff9c,%r15d
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mulsd  %xmm0,%xmm0
divsd  0xe56(%rip),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x1,%rbx
cmp    $0xb,%rbx
je     1235 <chi_square_test+0x105>
movsd  %xmm0,(%rsp)
mov    0x10(%rsp,%rbx,4),%r15d
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
mulsd  0xe0e(%rip),%xmm0
ucomisd 0xe16(%rip),%xmm0
jbe    1190 <chi_square_test+0x60>
mov    $0x1,%ebp
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    $0x2a,%edi
call   1030 <putchar@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
add    $0x1,%ebp
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1210 <chi_square_test+0xe0>
jmp    1190 <chi_square_test+0x60>
lea    0xde5(%rip),%rdi
mov    $0x1,%al
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%3d:%3d \00"
@.str.3 = [10 x i8] c"x 2 = %f\0A\00"
define void @chi_square_test() {
%1 = alloca [11 x i32]
%2 = bitcast [11 x i32]* %1 to i8*
%3 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 1
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ %14, %5 ], [ 1, %0 ]
%7 = tail call i32 (...) @rnd()
%8 = mul nsw i32 %7, 10
%9 = or i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
store i32 %13, i32* %11
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 1000
br i1 %15, label %16, label %5
16: ; preds = %5, %32
%17 = phi i64 [ %39, %32 ], [ 1, %5 ]
%18 = phi double [ %38, %32 ], [ 0.000000e+00, %5 ]
%19 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 %17
%20 = load i32, i32* %19
%21 = trunc i64 %17 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %20)
%23 = sitofp i32 %20 to double
%24 = fmul double %23, 4.000000e-01
%25 = fcmp ogt double %24, 0.000000e+00
br i1 %25, label %26, label %32
26: ; preds = %16, %26
%27 = phi i32 [ %29, %26 ], [ 0, %16 ]
%28 = tail call i32 @putchar(i32 42)
%29 = add nuw nsw i32 %27, 1
%30 = sitofp i32 %29 to double
%31 = fcmp ogt double %24, %30
br i1 %31, label %26, label %32
32: ; preds = %26, %16
%33 = tail call i32 @putchar(i32 10)
%34 = add nsw i32 %20, -100
%35 = sitofp i32 %34 to double
%36 = fmul double %35, %35
%37 = fdiv double %36, 1.000000e+02
%38 = fadd double %18, %37
%39 = add nuw nsw i64 %17, 1
%40 = icmp eq i64 %39, 11
br i1 %40, label %41, label %16
41: ; preds = %32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %38)
ret void
}