; LLVM IR from simbody/simbody :: SimTKmath/Integrators/src/CPodes/sundials/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 i32 @densePOTRF(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !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 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %13

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

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

25:                                               ; preds = %17
  %26 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %26, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %63, %25
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %66

31:                                               ; preds = %27
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %59, %31
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %62

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

59:                                               ; preds = %36
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %11, align 4, !tbaa !9
  br label %32, !llvm.loop !13

62:                                               ; preds = %32
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %9, align 4, !tbaa !9
  br label %27, !llvm.loop !15

66:                                               ; preds = %27
  br label %67

67:                                               ; preds = %66, %17
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %68, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !11
  store double %72, ptr %8, align 8, !tbaa !11
  %73 = load double, ptr %8, align 8, !tbaa !11
  %74 = fcmp ole double %73, 0.000000e+00
  br i1 %74, label %75, label %77

75:                                               ; preds = %67
  %76 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %76, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %101

77:                                               ; preds = %67
  %78 = load double, ptr %8, align 8, !tbaa !11
  %79 = call double @RSqrt(double noundef %78)
  store double %79, ptr %8, align 8, !tbaa !11
  %80 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %80, ptr %9, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %93, %77
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = load i32, ptr %5, align 4, !tbaa !9
  %84 = icmp slt i32 %82, %83
  br i1 %84, label %85, label %96

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

93:                                               ; preds = %85
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %9, align 4, !tbaa !9
  br label %81, !llvm.loop !16

96:                                               ; preds = %81
  br label %97

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

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

101:                                              ; preds = %100, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, 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 i32, ptr %3, align 4
  ret i32 %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

declare double @RSqrt(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 = { "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 = !{!"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}
!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: nounwind uwtable
define dso_local i32 @densePOTRF(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.lr.ph44.preheader, label %._crit_edge45

.lr.ph44.preheader:                               ; preds = %2
  %wide.trip.count62 = zext nneg i32 %1 to i64
  br label %.lr.ph44

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %._crit_edge
  %indvars.iv49 = phi i64 [ 0, %.lr.ph44.preheader ], [ %indvars.iv.next50, %._crit_edge ]
  %4 = sub nsw i64 %wide.trip.count62, %indvars.iv49
  %5 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv49
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not.not = icmp eq i64 %indvars.iv49, 0
  br i1 %.not.not, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph44
  %xtraiter = and i64 %indvars.iv49, 1
  %7 = icmp eq i64 %indvars.iv49, 1
  %unroll_iter = and i64 %indvars.iv49, 9223372036854775806
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %34
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %34 ], [ %indvars.iv49, %.preheader.preheader ]
  %8 = getelementptr inbounds double, ptr %6, i64 %indvars.iv51
  %.promoted = load double, ptr %8, align 8, !tbaa !9
  br i1 %7, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader, %.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.new ], [ 0, %.preheader ]
  %9 = phi double [ %25, %.preheader.new ], [ %.promoted, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %.preheader.new ], [ 0, %.preheader ]
  %10 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds double, ptr %11, i64 %indvars.iv51
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds double, ptr %11, i64 %indvars.iv49
  %15 = load double, ptr %14, align 8, !tbaa !9
  %16 = fneg double %13
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %15, double %9)
  store double %17, ptr %8, align 8, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %18 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.next
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i64 %indvars.iv51
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds double, ptr %19, i64 %indvars.iv49
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = fneg double %21
  %25 = tail call double @llvm.fmuladd.f64(double %24, double %23, double %17)
  store double %25, ptr %8, align 8, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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
  %indvars.iv.unr = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.1, %.preheader.new ]
  %.unr = phi double [ %.promoted, %.preheader ], [ %25, %.preheader.new ]
  br i1 %lcmp.mod.not, label %34, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %26 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv.unr
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds double, ptr %27, i64 %indvars.iv51
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds double, ptr %27, i64 %indvars.iv49
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fneg double %29
  %33 = tail call double @llvm.fmuladd.f64(double %32, double %31, double %.unr)
  store double %33, ptr %8, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next52, %wide.trip.count62
  br i1 %exitcond55.not, label %.loopexit, label %.preheader, !llvm.loop !13

.loopexit:                                        ; preds = %34, %.lr.ph44
  %35 = getelementptr inbounds double, ptr %6, i64 %indvars.iv49
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = fcmp ugt double %36, 0.000000e+00
  br i1 %37, label %.lr.ph.preheader, label %._crit_edge45.loopexit.split.loop.exit64

.lr.ph.preheader:                                 ; preds = %.loopexit
  %38 = tail call double @RSqrt(double noundef %36) #3
  %min.iters.check = icmp ult i64 %4, 2
  br i1 %min.iters.check, label %.lr.ph.preheader67, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %4, -2
  %ind.end = add i64 %indvars.iv49, %n.vec
  %broadcast.splatinsert = insertelement <2 x double> poison, double %38, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %39 = getelementptr double, ptr %6, i64 %indvars.iv49
  br label %vector.body

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

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

.lr.ph.preheader67:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv56.ph = phi i64 [ %indvars.iv49, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader67, %.lr.ph
  %indvars.iv56 = phi i64 [ %indvars.iv.next57, %.lr.ph ], [ %indvars.iv56.ph, %.lr.ph.preheader67 ]
  %43 = getelementptr inbounds double, ptr %6, i64 %indvars.iv56
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = fdiv double %44, %38
  store double %45, ptr %43, align 8, !tbaa !9
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %exitcond60.not = icmp eq i64 %indvars.iv.next57, %wide.trip.count62
  br i1 %exitcond60.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond63.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count62
  br i1 %exitcond63.not, label %._crit_edge45, label %.lr.ph44, !llvm.loop !18

._crit_edge45.loopexit.split.loop.exit64:         ; preds = %.loopexit
  %46 = trunc nuw nsw i64 %indvars.iv49 to i32
  br label %._crit_edge45

._crit_edge45:                                    ; preds = %._crit_edge, %._crit_edge45.loopexit.split.loop.exit64, %2
  %.035 = phi i32 [ 0, %2 ], [ %46, %._crit_edge45.loopexit.split.loop.exit64 ], [ 0, %._crit_edge ]
  ret i32 %.035
}

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

declare double @RSqrt(double noundef) local_unnamed_addr #2

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 = { "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 = !{!"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