; LLVM IR from stan-dev/math :: lib/sundials_6.1.1/src/sundials (sundials_dense)

; 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: nounwind uwtable
define dso_local i64 @SUNDlsMat_densePOTRF(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %97, %2
  %14 = load i64, ptr %10, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %17, label %100

17:                                               ; preds = %13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %18, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = icmp sgt i64 %22, 0
  br i1 %23, label %24, label %62

24:                                               ; preds = %17
  %25 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %25, ptr %9, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %58, %24
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = icmp slt i64 %27, %28
  br i1 %29, label %30, label %61

30:                                               ; preds = %26
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %54, %30
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = load i64, ptr %10, align 8, !tbaa !9
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %35, label %57

35:                                               ; preds = %31
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = getelementptr inbounds ptr, ptr %36, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds double, ptr %40, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %10, align 8, !tbaa !9
  %46 = getelementptr inbounds double, ptr %44, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = getelementptr inbounds double, ptr %48, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = fneg double %43
  %53 = call double @llvm.fmuladd.f64(double %52, double %47, double %51)
  store double %53, ptr %50, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %35
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %11, align 8, !tbaa !9
  br label %31, !llvm.loop !13

57:                                               ; preds = %31
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %9, align 8, !tbaa !9
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %9, align 8, !tbaa !9
  br label %26, !llvm.loop !15

61:                                               ; preds = %26
  br label %62

62:                                               ; preds = %61, %17
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i64, ptr %10, align 8, !tbaa !9
  %65 = getelementptr inbounds double, ptr %63, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !11
  store double %66, ptr %8, align 8, !tbaa !11
  %67 = load double, ptr %8, align 8, !tbaa !11
  %68 = fcmp ole double %67, 0.000000e+00
  br i1 %68, label %69, label %72

69:                                               ; preds = %62
  %70 = load i64, ptr %10, align 8, !tbaa !9
  %71 = add nsw i64 %70, 1
  store i64 %71, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %101

72:                                               ; preds = %62
  %73 = load double, ptr %8, align 8, !tbaa !11
  %74 = fcmp ole double %73, 0.000000e+00
  br i1 %74, label %75, label %76

75:                                               ; preds = %72
  br label %79

76:                                               ; preds = %72
  %77 = load double, ptr %8, align 8, !tbaa !11
  %78 = call double @sqrt(double noundef %77) #4
  br label %79

79:                                               ; preds = %76, %75
  %80 = phi double [ 0.000000e+00, %75 ], [ %78, %76 ]
  store double %80, ptr %8, align 8, !tbaa !11
  %81 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %81, ptr %9, align 8, !tbaa !9
  br label %82

82:                                               ; preds = %93, %79
  %83 = load i64, ptr %9, align 8, !tbaa !9
  %84 = load i64, ptr %5, align 8, !tbaa !9
  %85 = icmp slt i64 %83, %84
  br i1 %85, label %86, label %96

86:                                               ; preds = %82
  %87 = load double, ptr %8, align 8, !tbaa !11
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = getelementptr inbounds double, ptr %88, i64 %89
  %91 = load double, ptr %90, align 8, !tbaa !11
  %92 = fdiv double %91, %87
  store double %92, ptr %90, align 8, !tbaa !11
  br label %93

93:                                               ; preds = %86
  %94 = load i64, ptr %9, align 8, !tbaa !9
  %95 = add nsw i64 %94, 1
  store i64 %95, ptr %9, align 8, !tbaa !9
  br label %82, !llvm.loop !16

96:                                               ; preds = %82
  br label %97

97:                                               ; preds = %96
  %98 = load i64, ptr %10, align 8, !tbaa !9
  %99 = add nsw i64 %98, 1
  store i64 %99, ptr %10, align 8, !tbaa !9
  br label %13, !llvm.loop !17

100:                                              ; preds = %13
  store i64 0, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %101

101:                                              ; preds = %100, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %102 = load i64, ptr %3, align 8
  ret i64 %102
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !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: nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local i64 @SUNDlsMat_densePOTRF(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i64 %1, 0
  br i1 %3, label %.lr.ph47, label %.loopexit40

.lr.ph47:                                         ; preds = %2, %._crit_edge
  %.03445 = phi i64 [ %55, %._crit_edge ], [ 0, %2 ]
  %4 = add nuw i64 %.03445, 1
  %smax = tail call i64 @llvm.smax.i64(i64 %1, i64 %4)
  %5 = sub nsw i64 %smax, %.03445
  %6 = getelementptr inbounds ptr, ptr %0, i64 %.03445
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not.not = icmp eq i64 %.03445, 0
  br i1 %.not.not, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph47
  %xtraiter = and i64 %.03445, 1
  %8 = icmp eq i64 %.03445, 1
  %unroll_iter = and i64 %.03445, 9223372036854775806
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %37
  %.03543 = phi i64 [ %38, %37 ], [ %.03445, %.preheader.preheader ]
  %9 = getelementptr inbounds double, ptr %7, i64 %.03543
  %.promoted = load double, ptr %9, align 8, !tbaa !9
  br i1 %8, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader, %.preheader.new
  %.042 = phi i64 [ %28, %.preheader.new ], [ 0, %.preheader ]
  %10 = phi double [ %27, %.preheader.new ], [ %.promoted, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %.preheader.new ], [ 0, %.preheader ]
  %11 = getelementptr inbounds ptr, ptr %0, i64 %.042
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %12, i64 %.03543
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds double, ptr %12, i64 %.03445
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = fneg double %14
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double %10)
  store double %18, ptr %9, align 8, !tbaa !9
  %19 = or disjoint i64 %.042, 1
  %20 = getelementptr inbounds ptr, ptr %0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds double, ptr %21, i64 %.03543
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds double, ptr %21, i64 %.03445
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fneg double %23
  %27 = tail call double @llvm.fmuladd.f64(double %26, double %25, double %18)
  store double %27, ptr %9, align 8, !tbaa !9
  %28 = add nuw nsw i64 %.042, 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 %.unr-lcssa, label %.preheader.new, !llvm.loop !11

.unr-lcssa:                                       ; preds = %.preheader.new, %.preheader
  %.042.unr = phi i64 [ 0, %.preheader ], [ %28, %.preheader.new ]
  %.unr = phi double [ %.promoted, %.preheader ], [ %27, %.preheader.new ]
  br i1 %lcmp.mod.not, label %37, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %29 = getelementptr inbounds ptr, ptr %0, i64 %.042.unr
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %30, i64 %.03543
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %30, i64 %.03445
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fneg double %32
  %36 = tail call double @llvm.fmuladd.f64(double %35, double %34, double %.unr)
  store double %36, ptr %9, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %38 = add nuw nsw i64 %.03543, 1
  %39 = icmp slt i64 %38, %1
  br i1 %39, label %.preheader, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %37, %.lr.ph47
  %40 = getelementptr inbounds double, ptr %7, i64 %.03445
  %41 = load double, ptr %40, align 8, !tbaa !9
  %42 = fcmp ugt double %41, 0.000000e+00
  br i1 %42, label %.lr.ph.preheader, label %43

43:                                               ; preds = %.loopexit
  %44 = add nuw nsw i64 %.03445, 1
  br label %.loopexit40

.lr.ph.preheader:                                 ; preds = %.loopexit
  %45 = tail call double @sqrt(double noundef %41) #4
  %min.iters.check = icmp ult i64 %5, 2
  br i1 %min.iters.check, label %.lr.ph.preheader52, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %5, -2
  %ind.end = add i64 %.03445, %n.vec
  %broadcast.splatinsert = insertelement <2 x double> poison, double %45, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %46 = getelementptr double, ptr %7, i64 %.03445
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %47 = getelementptr double, ptr %46, i64 %index
  %wide.load = load <2 x double>, ptr %47, align 8, !tbaa !9
  %48 = fdiv <2 x double> %wide.load, %broadcast.splat
  store <2 x double> %48, ptr %47, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 2
  %49 = icmp eq i64 %index.next, %n.vec
  br i1 %49, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %5, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader52

.lr.ph.preheader52:                               ; preds = %middle.block, %.lr.ph.preheader
  %.144.ph = phi i64 [ %.03445, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader52, %.lr.ph
  %.144 = phi i64 [ %53, %.lr.ph ], [ %.144.ph, %.lr.ph.preheader52 ]
  %50 = getelementptr inbounds double, ptr %7, i64 %.144
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fdiv double %51, %45
  store double %52, ptr %50, align 8, !tbaa !9
  %53 = add nuw nsw i64 %.144, 1
  %54 = icmp slt i64 %53, %1
  br i1 %54, label %.lr.ph, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %55 = add nuw nsw i64 %.03445, 1
  %exitcond49.not = icmp eq i64 %55, %1
  br i1 %exitcond49.not, label %.loopexit40, label %.lr.ph47, !llvm.loop !18

.loopexit40:                                      ; preds = %._crit_edge, %2, %43
  %.036 = phi i64 [ %44, %43 ], [ 0, %2 ], [ 0, %._crit_edge ]
  ret i64 %.036
}

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: write) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12, !15, !16}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !12, !16, !15}
!18 = distinct !{!18, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass