#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 chisquare(long *, double *, long, int, int *);
double get_rn();
double mytest(long n) {
  double temp;
  long actual[2] = {0, 0};
  double expected[2] = {0.5, 0.5};
  long i;
  int temp2;
  for (i = 0; i < n; i++) {
    temp = get_rn();
    if (temp > 0.5)
      actual[0]++;
    else
      actual[1]++;
  }
  return chisquare(actual, expected, n, 2, &temp2);
}


x86 assembly (clang, -O0):
<mytest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0xebd(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11ce <mytest+0x9e>
mov    $0x0,%al
call   1040 <get_rn@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ac <mytest+0x7c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b8 <mytest+0x88>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11bd <mytest+0x8d>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    116a <mytest+0x3a>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    $0x2,%ecx
lea    -0x3c(%rbp),%r8
call   1030 <chisquare@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mytest>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movapd 0xed3(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
test   %rdi,%rdi
jle    117e <mytest+0x5e>
mov    %r14,%r12
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <get_rn@plt>
xor    %eax,%eax
xor    %ecx,%ecx
ucomisd 0xe9d(%rip),%xmm0
setbe  %al
seta   %cl
add    %rcx,%r15
add    %rax,%rbx
add    $0xffffffffffffffff,%r12
jne    1150 <mytest+0x30>
mov    %rbx,0x8(%rsp)
mov    %r15,(%rsp)
mov    %rsp,%rdi
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%r8
mov    %r14,%rdx
mov    $0x2,%ecx
call   1030 <chisquare@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.mytest.expected = [2 x double] [double 5.000000e-01, double 5.000000e-01]
define double @mytest(i64 %0) {
%2 = alloca i64
%3 = alloca double
%4 = alloca [2 x i64]
%5 = alloca [2 x double]
%6 = alloca i64
%7 = alloca i32
store i64 %0, i64* %2
%8 = bitcast [2 x i64]* %4 to i8*
%9 = bitcast [2 x double]* %5 to i8*
store i64 0, i64* %6
br label %10
10: ; preds = %27, %1
%11 = load i64, i64* %6
%12 = load i64, i64* %2
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = call double (...) @get_rn()
store double %15, double* %3
%16 = load double, double* %3
%17 = fcmp ogt double %16, 5.000000e-01
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%20 = load i64, i64* %19
%21 = add nsw i64 %20, 1
store i64 %21, i64* %19
br label %26
22: ; preds = %14
%23 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 1
%24 = load i64, i64* %23
%25 = add nsw i64 %24, 1
store i64 %25, i64* %23
br label %26
26: ; preds = %22, %18
br label %27
27: ; preds = %26
%28 = load i64, i64* %6
%29 = add nsw i64 %28, 1
store i64 %29, i64* %6
br label %10
30: ; preds = %10
%31 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%32 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%33 = load i64, i64* %2
%34 = call double @chisquare(i64* %31, double* %32, i64 %33, i32 2, i32* %7)
ret double %34
}

LLVM IR (-O2):
@__const.mytest.expected = [2 x double] [double 5.000000e-01, double 5.000000e-01]
define double @mytest(i64 %0) {
%2 = alloca [2 x i64]
%3 = alloca [2 x double]
%4 = alloca i32
%5 = bitcast [2 x i64]* %2 to i8*
%6 = bitcast [2 x double]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = icmp sgt i64 %0, 0
br i1 %8, label %9, label %26
9: ; preds = %1
%10 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 1
%11 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 0
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %19, %12 ]
%14 = phi i64 [ 0, %9 ], [ %22, %12 ]
%15 = phi i64 [ 0, %9 ], [ %23, %12 ]
%16 = tail call double (...) @get_rn()
%17 = fcmp ogt double %16, 5.000000e-01
%18 = zext i1 %17 to i64
%19 = add nuw nsw i64 %13, %18
%20 = xor i1 %17, true
%21 = zext i1 %20 to i64
%22 = add nuw nsw i64 %14, %21
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, %0
br i1 %24, label %25, label %12
25: ; preds = %12
store i64 %22, i64* %10
store i64 %19, i64* %11
br label %26
26: ; preds = %25, %1
%27 = getelementptr inbounds [2 x i64], [2 x i64]* %2, i64 0, i64 0
%28 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 0
%29 = call double @chisquare(i64* %27, double* %28, i64 %0, i32 2, i32* %4)
ret double %29
}