; LLVM IR from 3ki5tj/minmd :: src/lib/minmd_math/rng (test)

; 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"

@.str.8 = external hidden unnamed_addr constant [45 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @rng_gauss(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @rng_chisqr(ptr noundef, double noundef) #1

declare i32 @printf(ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
define dso_local void @test_rng_chisqr(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1000000, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 10, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store double 0.000000e+00, ptr %12, align 8, !tbaa !11
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %47, %1
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 1000000
  br i1 %15, label %16, label %50

16:                                               ; preds = %13
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call double @rng_chisqr(ptr noundef %17, double noundef 1.000000e+01)
  store double %18, ptr %7, align 8, !tbaa !11
  %19 = load double, ptr %7, align 8, !tbaa !11
  %20 = load double, ptr %8, align 8, !tbaa !11
  %21 = fadd double %20, %19
  store double %21, ptr %8, align 8, !tbaa !11
  %22 = load double, ptr %7, align 8, !tbaa !11
  %23 = load double, ptr %7, align 8, !tbaa !11
  %24 = load double, ptr %9, align 8, !tbaa !11
  %25 = call double @llvm.fmuladd.f64(double %22, double %23, double %24)
  store double %25, ptr %9, align 8, !tbaa !11
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %36, %16
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 10
  br i1 %28, label %29, label %39

29:                                               ; preds = %26
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call double @rng_gauss(ptr noundef %30)
  store double %31, ptr %7, align 8, !tbaa !11
  %32 = load double, ptr %7, align 8, !tbaa !11
  %33 = load double, ptr %7, align 8, !tbaa !11
  %34 = load double, ptr %10, align 8, !tbaa !11
  %35 = call double @llvm.fmuladd.f64(double %32, double %33, double %34)
  store double %35, ptr %10, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %29
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %4, align 4, !tbaa !9
  br label %26, !llvm.loop !13

39:                                               ; preds = %26
  %40 = load double, ptr %10, align 8, !tbaa !11
  %41 = load double, ptr %11, align 8, !tbaa !11
  %42 = fadd double %41, %40
  store double %42, ptr %11, align 8, !tbaa !11
  %43 = load double, ptr %10, align 8, !tbaa !11
  %44 = load double, ptr %10, align 8, !tbaa !11
  %45 = load double, ptr %12, align 8, !tbaa !11
  %46 = call double @llvm.fmuladd.f64(double %43, double %44, double %45)
  store double %46, ptr %12, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %39
  %48 = load i32, ptr %3, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %3, align 4, !tbaa !9
  br label %13, !llvm.loop !15

50:                                               ; preds = %13
  %51 = load double, ptr %8, align 8, !tbaa !11
  %52 = fdiv double %51, 1.000000e+06
  store double %52, ptr %7, align 8, !tbaa !11
  %53 = load double, ptr %11, align 8, !tbaa !11
  %54 = fdiv double %53, 1.000000e+06
  store double %54, ptr %10, align 8, !tbaa !11
  %55 = load double, ptr %7, align 8, !tbaa !11
  %56 = load double, ptr %9, align 8, !tbaa !11
  %57 = fdiv double %56, 1.000000e+06
  %58 = load double, ptr %7, align 8, !tbaa !11
  %59 = load double, ptr %7, align 8, !tbaa !11
  %60 = fneg double %58
  %61 = call double @llvm.fmuladd.f64(double %60, double %59, double %57)
  %62 = call double @sqrt(double noundef %61) #5
  %63 = load double, ptr %10, align 8, !tbaa !11
  %64 = load double, ptr %12, align 8, !tbaa !11
  %65 = fdiv double %64, 1.000000e+06
  %66 = load double, ptr %10, align 8, !tbaa !11
  %67 = load double, ptr %10, align 8, !tbaa !11
  %68 = fneg double %66
  %69 = call double @llvm.fmuladd.f64(double %68, double %67, double %65)
  %70 = call double @sqrt(double noundef %69) #5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, double noundef %55, double noundef %62, double noundef %63, double noundef %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 #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 = !{!"int", !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"

@.str.8 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @rng_gauss(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @rng_chisqr(ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @test_rng_chisqr(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %1, %2
  %.02839 = phi double [ 0.000000e+00, %1 ], [ %26, %2 ]
  %.03137 = phi double [ 0.000000e+00, %1 ], [ %5, %2 ]
  %.03236 = phi i32 [ 0, %1 ], [ %30, %2 ]
  %3 = phi <2 x double> [ zeroinitializer, %1 ], [ %29, %2 ]
  %4 = tail call double @rng_chisqr(ptr noundef %0, double noundef 1.000000e+01)
  %5 = fadd double %.03137, %4
  %6 = tail call double @rng_gauss(ptr noundef %0)
  %7 = tail call double @llvm.fmuladd.f64(double %6, double %6, double 0.000000e+00)
  %8 = tail call double @rng_gauss(ptr noundef %0)
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %7)
  %10 = tail call double @rng_gauss(ptr noundef %0)
  %11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %9)
  %12 = tail call double @rng_gauss(ptr noundef %0)
  %13 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %11)
  %14 = tail call double @rng_gauss(ptr noundef %0)
  %15 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %13)
  %16 = tail call double @rng_gauss(ptr noundef %0)
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %15)
  %18 = tail call double @rng_gauss(ptr noundef %0)
  %19 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %17)
  %20 = tail call double @rng_gauss(ptr noundef %0)
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %19)
  %22 = tail call double @rng_gauss(ptr noundef %0)
  %23 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %21)
  %24 = tail call double @rng_gauss(ptr noundef %0)
  %25 = tail call double @llvm.fmuladd.f64(double %24, double %24, double %23)
  %26 = fadd double %.02839, %25
  %27 = insertelement <2 x double> poison, double %25, i64 0
  %28 = insertelement <2 x double> %27, double %4, i64 1
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> %28, <2 x double> %3)
  %30 = add nuw nsw i32 %.03236, 1
  %exitcond.not = icmp eq i32 %30, 1000000
  br i1 %exitcond.not, label %31, label %2, !llvm.loop !5

31:                                               ; preds = %2
  %32 = fdiv double %5, 1.000000e+06
  %33 = fdiv double %26, 1.000000e+06
  %34 = extractelement <2 x double> %29, i64 1
  %35 = fdiv double %34, 1.000000e+06
  %36 = fneg double %32
  %37 = tail call double @llvm.fmuladd.f64(double %36, double %32, double %35)
  %38 = tail call double @sqrt(double noundef %37) #5
  %39 = extractelement <2 x double> %29, i64 0
  %40 = fdiv double %39, 1.000000e+06
  %41 = fneg double %33
  %42 = tail call double @llvm.fmuladd.f64(double %41, double %33, double %40)
  %43 = tail call double @sqrt(double noundef %42) #5
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, double noundef %32, double noundef %38, double noundef %33, double noundef %43)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { nofree 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass