; LLVM IR from Derek-TH-Wang/quadruped_ctrl :: src/JCQP/CholeskyDenseSolver.ll (ZN19CholeskyDenseSolverIdE8setupAVXEPdS1_S1_m)

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

%class.CholeskyDenseSolver = type <{ %"class.Eigen::Matrix", ptr, ptr, %"class.Eigen::Matrix.3", ptr, i64, i8, [7 x i8] }>
%"class.Eigen::Matrix" = type { %"class.Eigen::PlainObjectBase" }
%"class.Eigen::PlainObjectBase" = type { %"class.Eigen::DenseStorage" }
%"class.Eigen::DenseStorage" = type { ptr, i64, i64 }
%"class.Eigen::Matrix.3" = type { %"class.Eigen::PlainObjectBase.4" }
%"class.Eigen::PlainObjectBase.4" = type { %"class.Eigen::DenseStorage.11" }
%"class.Eigen::DenseStorage.11" = type { ptr, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN19CholeskyDenseSolverIdE8setupAVXEPdS1_S1_m(ptr noundef nonnull align 8 dereferenceable(73) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4) #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %18 = getelementptr inbounds %class.CholeskyDenseSolver, ptr %17, i32 0, i32 5
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = load i64, ptr %10, align 8, !tbaa !9
  %21 = sub i64 %19, %20
  %22 = sub i64 %21, 1
  store i64 %22, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %23 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %23, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %24

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

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %64

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %14, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %15, align 8, !tbaa !9
  %33 = getelementptr inbounds %class.CholeskyDenseSolver, ptr %17, i32 0, i32 5
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = mul nsw i64 %32, %34
  %36 = getelementptr inbounds double, ptr %31, i64 %35
  store ptr %36, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %57, %29
  %38 = load i64, ptr %16, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %41, label %60

41:                                               ; preds = %37
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = load double, ptr %42, align 8, !tbaa !20
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load double, ptr %44, align 8, !tbaa !20
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = getelementptr inbounds double, ptr %46, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !20
  %50 = fneg double %45
  %51 = call double @llvm.fmuladd.f64(double %50, double %49, double %43)
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  store double %51, ptr %52, align 8, !tbaa !20
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %53, i32 1
  store ptr %54, ptr %14, align 8, !tbaa !5
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %55, i32 1
  store ptr %56, ptr %13, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %41
  %58 = load i64, ptr %16, align 8, !tbaa !9
  %59 = add nsw i64 %58, 1
  store i64 %59, ptr %16, align 8, !tbaa !9
  br label %37, !llvm.loop !22

60:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %15, align 8, !tbaa !9
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %15, align 8, !tbaa !9
  br label %24, !llvm.loop !24

64:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

; 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

attributes #0 = { mustprogress 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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 64}
!12 = !{!"_ZTS19CholeskyDenseSolverIdE", !13, i64 0, !6, i64 24, !6, i64 32, !16, i64 40, !6, i64 56, !10, i64 64, !19, i64 72}
!13 = !{!"_ZTSN5Eigen6MatrixIdLin1ELin1ELi0ELin1ELin1EEE", !14, i64 0}
!14 = !{!"_ZTSN5Eigen15PlainObjectBaseINS_6MatrixIdLin1ELin1ELi0ELin1ELin1EEEEE", !15, i64 0}
!15 = !{!"_ZTSN5Eigen12DenseStorageIdLin1ELin1ELin1ELi0EEE", !6, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!"_ZTSN5Eigen6MatrixIdLin1ELi1ELi0ELin1ELi1EEE", !17, i64 0}
!17 = !{!"_ZTSN5Eigen15PlainObjectBaseINS_6MatrixIdLin1ELi1ELi0ELin1ELi1EEEEE", !18, i64 0}
!18 = !{!"_ZTSN5Eigen12DenseStorageIdLin1ELin1ELi1ELi0EEE", !6, i64 0, !10, i64 8}
!19 = !{!"bool", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN19CholeskyDenseSolverIdE8setupAVXEPdS1_S1_m(ptr nocapture noundef nonnull readonly align 8 dereferenceable(73) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2, ptr nocapture noundef readonly %3, i64 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = xor i64 %4, -1
  %9 = add i64 %7, %8
  %10 = icmp sgt i64 %4, 0
  %11 = icmp sgt i64 %9, 0
  %or.cond = select i1 %10, i1 %11, i1 false
  br i1 %or.cond, label %.lr.ph.us.preheader, label %._crit_edge27

.lr.ph.us.preheader:                              ; preds = %5
  %12 = shl i64 %7, 3
  %13 = add i64 %12, -8
  %14 = shl i64 %4, 3
  %15 = sub i64 %13, %14
  %scevgep = getelementptr i8, ptr %2, i64 %15
  %16 = mul i64 %13, %4
  %17 = getelementptr i8, ptr %1, i64 %16
  %scevgep30 = getelementptr i8, ptr %17, i64 -8
  %scevgep31 = getelementptr i8, ptr %3, i64 %14
  %min.iters.check = icmp ult i64 %9, 4
  %bound0 = icmp ugt ptr %scevgep30, %2
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  %stride.check = icmp slt i64 %12, 0
  %18 = or i1 %found.conflict, %stride.check
  %bound032 = icmp ugt ptr %scevgep31, %2
  %bound133 = icmp ugt ptr %scevgep, %3
  %found.conflict34 = and i1 %bound032, %bound133
  %conflict.rdx = or i1 %18, %found.conflict34
  %n.vec = and i64 %9, 9223372036854775804
  %19 = shl i64 %n.vec, 3
  %ind.end = getelementptr i8, ptr %2, i64 %19
  %20 = shl i64 %n.vec, 3
  %cmp.n = icmp eq i64 %9, %n.vec
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01824.us = phi i64 [ %40, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %21 = mul nsw i64 %.01824.us, %7
  %22 = getelementptr inbounds double, ptr %1, i64 %21
  %23 = getelementptr inbounds double, ptr %3, i64 %.01824.us
  %brmerge = select i1 %min.iters.check, i1 true, i1 %conflict.rdx
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %ind.end36 = getelementptr i8, ptr %22, i64 %20
  %24 = load double, ptr %23, align 8, !tbaa !18, !alias.scope !20
  %broadcast.splatinsert45 = insertelement <2 x double> poison, double %24, i64 0
  %broadcast.splat46 = shufflevector <2 x double> %broadcast.splatinsert45, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 3
  %next.gep = getelementptr i8, ptr %2, i64 %offset.idx
  %offset.idx39 = shl i64 %index, 3
  %next.gep40 = getelementptr i8, ptr %22, i64 %offset.idx39
  %25 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <2 x double>, ptr %next.gep, align 8, !tbaa !18, !alias.scope !23, !noalias !25
  %wide.load42 = load <2 x double>, ptr %25, align 8, !tbaa !18, !alias.scope !23, !noalias !25
  %26 = getelementptr i8, ptr %next.gep40, i64 16
  %wide.load43 = load <2 x double>, ptr %next.gep40, align 8, !tbaa !18, !alias.scope !27
  %wide.load44 = load <2 x double>, ptr %26, align 8, !tbaa !18, !alias.scope !27
  %27 = fneg <2 x double> %wide.load43
  %28 = fneg <2 x double> %wide.load44
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %broadcast.splat46, <2 x double> %wide.load)
  %30 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> %broadcast.splat46, <2 x double> %wide.load42)
  store <2 x double> %29, ptr %next.gep, align 8, !tbaa !18, !alias.scope !23, !noalias !25
  store <2 x double> %30, ptr %25, align 8, !tbaa !18, !alias.scope !23, !noalias !25
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !28

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph.us, %middle.block
  %.023.us.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  %.01922.us.ph = phi ptr [ %2, %.lr.ph.us ], [ %ind.end, %middle.block ]
  %.02021.us.ph = phi ptr [ %22, %.lr.ph.us ], [ %ind.end36, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.023.us = phi i64 [ %39, %scalar.ph ], [ %.023.us.ph, %scalar.ph.preheader ]
  %.01922.us = phi ptr [ %37, %scalar.ph ], [ %.01922.us.ph, %scalar.ph.preheader ]
  %.02021.us = phi ptr [ %38, %scalar.ph ], [ %.02021.us.ph, %scalar.ph.preheader ]
  %32 = load double, ptr %.01922.us, align 8, !tbaa !18
  %33 = load double, ptr %.02021.us, align 8, !tbaa !18
  %34 = load double, ptr %23, align 8, !tbaa !18
  %35 = fneg double %33
  %36 = tail call double @llvm.fmuladd.f64(double %35, double %34, double %32)
  store double %36, ptr %.01922.us, align 8, !tbaa !18
  %37 = getelementptr inbounds i8, ptr %.01922.us, i64 8
  %38 = getelementptr inbounds i8, ptr %.02021.us, i64 8
  %39 = add nuw nsw i64 %.023.us, 1
  %exitcond.not = icmp eq i64 %39, %9
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !32

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %40 = add nuw nsw i64 %.01824.us, 1
  %exitcond29.not = icmp eq i64 %40, %4
  br i1 %exitcond29.not, label %._crit_edge27, label %.lr.ph.us, !llvm.loop !33

._crit_edge27:                                    ; preds = %._crit_edge.us, %5
  ret void
}

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

; 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>) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !13, i64 64}
!6 = !{!"_ZTS19CholeskyDenseSolverIdE", !7, i64 0, !10, i64 24, !10, i64 32, !14, i64 40, !10, i64 56, !13, i64 64, !17, i64 72}
!7 = !{!"_ZTSN5Eigen6MatrixIdLin1ELin1ELi0ELin1ELin1EEE", !8, i64 0}
!8 = !{!"_ZTSN5Eigen15PlainObjectBaseINS_6MatrixIdLin1ELin1ELi0ELin1ELin1EEEEE", !9, i64 0}
!9 = !{!"_ZTSN5Eigen12DenseStorageIdLin1ELin1ELin1ELi0EEE", !10, i64 0, !13, i64 8, !13, i64 16}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"_ZTSN5Eigen6MatrixIdLin1ELi1ELi0ELin1ELi1EEE", !15, i64 0}
!15 = !{!"_ZTSN5Eigen15PlainObjectBaseINS_6MatrixIdLin1ELi1ELi0ELin1ELi1EEEEE", !16, i64 0}
!16 = !{!"_ZTSN5Eigen12DenseStorageIdLin1ELin1ELi1ELi0EEE", !10, i64 0, !13, i64 8}
!17 = !{!"bool", !11, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !11, i64 0}
!20 = !{!21}
!21 = distinct !{!21, !22}
!22 = distinct !{!22, !"LVerDomain"}
!23 = !{!24}
!24 = distinct !{!24, !22}
!25 = !{!26, !21}
!26 = distinct !{!26, !22}
!27 = !{!26}
!28 = distinct !{!28, !29, !30, !31}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!"llvm.loop.isvectorized", i32 1}
!31 = !{!"llvm.loop.unroll.runtime.disable"}
!32 = distinct !{!32, !29, !30}
!33 = distinct !{!33, !29}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass