; 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 @calculate_entropy(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 i64, align 8
  %8 = alloca i64, align 8
  %9 = 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) #5
  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) #5
  store double 0.000000e+00, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %24, %2
  %11 = load i64, ptr %7, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %27

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = getelementptr inbounds i64, ptr %16, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = and i64 %19, 255
  %21 = getelementptr inbounds [256 x i64], ptr %5, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %15
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %7, align 8, !tbaa !9
  br label %10, !llvm.loop !13

27:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %52, %27
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = icmp ult i64 %29, 256
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %55

32:                                               ; preds = %28
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds [256 x i64], ptr %5, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = icmp ugt i64 %35, 0
  br i1 %36, label %37, label %51

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

51:                                               ; preds = %37, %32
  br label %52

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

55:                                               ; preds = %31
  %56 = load double, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr %5) #5
  ret double %56
}

; Function Attrs: nounwind
declare double @log2(double noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

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 "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 nounwind memory(write, argmem: readwrite) uwtable
define dso_local double @calculate_entropy(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) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) %3, i8 0, i64 2048, i1 false)
  %.not20 = icmp eq i64 %1, 0
  br i1 %.not20, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %1, 1
  %4 = icmp eq i64 %1, 1
  br i1 %4, label %.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.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %.01417.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

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

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.loopexit.unr-lcssa, %2
  %11 = uitofp i64 %1 to double
  br label %27

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01417 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %25, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %12 = getelementptr inbounds i64, ptr %0, i64 %.01417
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = and i64 %13, 255
  %15 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add i64 %16, 1
  store i64 %17, ptr %15, align 8, !tbaa !5
  %18 = or disjoint i64 %.01417, 1
  %19 = getelementptr inbounds i64, ptr %0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = and i64 %20, 255
  %22 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = add i64 %23, 1
  store i64 %24, ptr %22, align 8, !tbaa !5
  %25 = add nuw i64 %.01417, 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.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

26:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %3) #5
  ret double %.1

27:                                               ; preds = %.preheader, %36
  %.019 = phi double [ 0.000000e+00, %.preheader ], [ %.1, %36 ]
  %.01318 = phi i64 [ 0, %.preheader ], [ %37, %36 ]
  %28 = getelementptr inbounds [256 x i64], ptr %3, i64 0, i64 %.01318
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %.not = icmp eq i64 %29, 0
  br i1 %.not, label %36, label %30

30:                                               ; preds = %27
  %31 = uitofp i64 %29 to double
  %32 = fdiv double %31, %11
  %33 = tail call double @log2(double noundef %32) #5
  %34 = fneg double %32
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %33, double %.019)
  br label %36

36:                                               ; preds = %27, %30
  %.1 = phi double [ %35, %30 ], [ %.019, %27 ]
  %37 = add nuw nsw i64 %.01318, 1
  %exitcond21.not = icmp eq i64 %37, 256
  br i1 %exitcond21.not, label %26, label %27, !llvm.loop !11
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log2(double noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind memory(write, argmem: readwrite) 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 = { mustprogress nofree nounwind willreturn memory(write) "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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass