; LLVM IR from tsotchke/quantum_rng :: tests/statistical (statistical_tests)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local double @chi_square_test(ptr noundef %0, i64 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca [256 x i64], align 16
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %5) #3
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 2048, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = udiv i64 %11, 256
  %13 = uitofp i64 %12 to double
  store double %13, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %28, %2
  %15 = load i64, ptr %8, align 8, !tbaa !9
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %31

19:                                               ; preds = %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = getelementptr inbounds i64, ptr %20, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = and i64 %23, 255
  %25 = getelementptr inbounds [256 x i64], ptr %5, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = add i64 %26, 1
  store i64 %27, ptr %25, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %19
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = add i64 %29, 1
  store i64 %30, ptr %8, align 8, !tbaa !9
  br label %14, !llvm.loop !13

31:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %50, %31
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = icmp ult i64 %33, 256
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %53

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = getelementptr inbounds [256 x i64], ptr %5, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = uitofp i64 %39 to double
  %41 = load double, ptr %6, align 8, !tbaa !11
  %42 = fsub double %40, %41
  store double %42, ptr %10, align 8, !tbaa !11
  %43 = load double, ptr %10, align 8, !tbaa !11
  %44 = load double, ptr %10, align 8, !tbaa !11
  %45 = fmul double %43, %44
  %46 = load double, ptr %6, align 8, !tbaa !11
  %47 = fdiv double %45, %46
  %48 = load double, ptr %7, align 8, !tbaa !11
  %49 = fadd double %48, %47
  store double %49, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %50

50:                                               ; preds = %36
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %9, align 8, !tbaa !9
  br label %32, !llvm.loop !15

53:                                               ; preds = %35
  %54 = load double, ptr %7, align 8, !tbaa !11
  %55 = fdiv double %54, 2.550000e+02
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 2048, ptr %5) #3
  ret double %55
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @chi_square_test(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = alloca [256 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) %3, i8 0, i64 2048, i1 false)
  %4 = lshr i64 %1, 8
  %5 = uitofp nneg i64 %4 to double
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.preheader.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %1, 1
  %6 = icmp eq i64 %1, 1
  br i1 %6, label %.preheader.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %1, -2
  br label %.lr.ph

.preheader.preheader.loopexit.unr-lcssa:          ; preds = %.lr.ph, %.lr.ph.preheader
  %.01516.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.preheader.loopexit.unr-lcssa
  %7 = getelementptr inbounds i64, ptr %0, i64 %.01516.unr
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = and i64 %8, 255
  %10 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = add i64 %11, 1
  store i64 %12, ptr %10, align 8, !tbaa !5
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph.epil, %.preheader.preheader.loopexit.unr-lcssa, %2
  br label %.preheader

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01516 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %13 = getelementptr inbounds i64, ptr %0, i64 %.01516
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = and i64 %14, 255
  %16 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = add i64 %17, 1
  store i64 %18, ptr %16, align 8, !tbaa !5
  %19 = or disjoint i64 %.01516, 1
  %20 = getelementptr inbounds i64, ptr %0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = and i64 %21, 255
  %23 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add i64 %24, 1
  store i64 %25, ptr %23, align 8, !tbaa !5
  %26 = add nuw i64 %.01516, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

27:                                               ; preds = %.preheader
  %28 = fdiv double %43, 2.550000e+02
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %3) #3
  ret double %28

.preheader:                                       ; preds = %.preheader, %.preheader.preheader
  %.018 = phi double [ 0.000000e+00, %.preheader.preheader ], [ %43, %.preheader ]
  %.01417 = phi i64 [ 0, %.preheader.preheader ], [ %44, %.preheader ]
  %29 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %.01417
  %30 = load i64, ptr %29, align 16, !tbaa !5
  %31 = uitofp i64 %30 to double
  %32 = fsub double %31, %5
  %33 = fmul double %32, %32
  %34 = fdiv double %33, %5
  %35 = fadd double %.018, %34
  %36 = or disjoint i64 %.01417, 1
  %37 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = uitofp i64 %38 to double
  %40 = fsub double %39, %5
  %41 = fmul double %40, %40
  %42 = fdiv double %41, %5
  %43 = fadd double %35, %42
  %44 = add nuw nsw i64 %.01417, 2
  %exitcond19.not.1 = icmp eq i64 %44, 256
  br i1 %exitcond19.not.1, label %27, label %.preheader, !llvm.loop !11
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree norecurse nosync nounwind memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass