; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/DSP/Source/MatrixFunctions (MatrixFunctions)

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

%struct.arm_matrix_instance_f64 = type { i16, i16, ptr }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_mat_solve_lower_triangular_f64(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca double, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.arm_matrix_instance_f64, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  store ptr %23, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.arm_matrix_instance_f64, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  store ptr %26, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.arm_matrix_instance_f64, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  store ptr %29, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.arm_matrix_instance_f64, ptr %30, i32 0, i32 0
  %32 = load i16, ptr %31, align 8, !tbaa !12
  %33 = zext i16 %32 to i32
  store i32 %33, ptr %12, align 4, !tbaa !13
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.arm_matrix_instance_f64, ptr %34, i32 0, i32 1
  %36 = load i16, ptr %35, align 2, !tbaa !15
  %37 = zext i16 %36 to i32
  store i32 %37, ptr %13, align 4, !tbaa !13
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %122, %3
  %39 = load i32, ptr %10, align 4, !tbaa !13
  %40 = load i32, ptr %13, align 4, !tbaa !13
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %125

42:                                               ; preds = %38
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !13
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  store ptr %46, ptr %18, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %47

47:                                               ; preds = %118, %42
  %48 = load i32, ptr %9, align 4, !tbaa !13
  %49 = load i32, ptr %12, align 4, !tbaa !13
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %121

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %52 = load ptr, ptr %18, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !13
  %54 = load i32, ptr %13, align 4, !tbaa !13
  %55 = mul nsw i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %52, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !16
  store double %58, ptr %19, align 8, !tbaa !16
  %59 = load ptr, ptr %15, align 8, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !13
  %61 = load i32, ptr %9, align 4, !tbaa !13
  %62 = mul nsw i32 %60, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %59, i64 %63
  store ptr %64, ptr %17, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %65

65:                                               ; preds = %87, %51
  %66 = load i32, ptr %11, align 4, !tbaa !13
  %67 = load i32, ptr %9, align 4, !tbaa !13
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %90

69:                                               ; preds = %65
  %70 = load ptr, ptr %17, align 8, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !13
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !16
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  %76 = load i32, ptr %13, align 4, !tbaa !13
  %77 = load i32, ptr %11, align 4, !tbaa !13
  %78 = mul nsw i32 %76, %77
  %79 = load i32, ptr %10, align 4, !tbaa !13
  %80 = add nsw i32 %78, %79
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %75, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !16
  %84 = load double, ptr %19, align 8, !tbaa !16
  %85 = fneg double %74
  %86 = call double @llvm.fmuladd.f64(double %85, double %83, double %84)
  store double %86, ptr %19, align 8, !tbaa !16
  br label %87

87:                                               ; preds = %69
  %88 = load i32, ptr %11, align 4, !tbaa !13
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %11, align 4, !tbaa !13
  br label %65, !llvm.loop !18

90:                                               ; preds = %65
  %91 = load ptr, ptr %17, align 8, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !13
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds double, ptr %91, i64 %93
  %95 = load double, ptr %94, align 8, !tbaa !16
  %96 = fcmp oeq double %95, 0.000000e+00
  br i1 %96, label %97, label %98

97:                                               ; preds = %90
  store i32 -5, ptr %4, align 4
  store i32 1, ptr %20, align 4
  br label %115

98:                                               ; preds = %90
  %99 = load double, ptr %19, align 8, !tbaa !16
  %100 = load ptr, ptr %17, align 8, !tbaa !5
  %101 = load i32, ptr %9, align 4, !tbaa !13
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds double, ptr %100, i64 %102
  %104 = load double, ptr %103, align 8, !tbaa !16
  %105 = fdiv double %99, %104
  store double %105, ptr %19, align 8, !tbaa !16
  %106 = load double, ptr %19, align 8, !tbaa !16
  %107 = load ptr, ptr %14, align 8, !tbaa !5
  %108 = load i32, ptr %9, align 4, !tbaa !13
  %109 = load i32, ptr %13, align 4, !tbaa !13
  %110 = mul nsw i32 %108, %109
  %111 = load i32, ptr %10, align 4, !tbaa !13
  %112 = add nsw i32 %110, %111
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds double, ptr %107, i64 %113
  store double %106, ptr %114, align 8, !tbaa !16
  store i32 0, ptr %20, align 4
  br label %115

115:                                              ; preds = %98, %97
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  %116 = load i32, ptr %20, align 4
  switch i32 %116, label %126 [
    i32 0, label %117
  ]

117:                                              ; preds = %115
  br label %118

118:                                              ; preds = %117
  %119 = load i32, ptr %9, align 4, !tbaa !13
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %9, align 4, !tbaa !13
  br label %47, !llvm.loop !20

121:                                              ; preds = %47
  br label %122

122:                                              ; preds = %121
  %123 = load i32, ptr %10, align 4, !tbaa !13
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %10, align 4, !tbaa !13
  br label %38, !llvm.loop !21

125:                                              ; preds = %38
  store i32 0, ptr %8, align 4, !tbaa !13
  store i32 0, ptr %20, align 4
  br label %126

126:                                              ; preds = %125, %115
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %127 = load i32, ptr %20, align 4
  switch i32 %127, label %130 [
    i32 0, label %128
  ]

128:                                              ; preds = %126
  %129 = load i32, ptr %8, align 4, !tbaa !13
  store i32 %129, ptr %4, align 4
  store i32 1, ptr %20, align 4
  br label %130

130:                                              ; preds = %128, %126
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %131 = load i32, ptr %4, align 4
  ret i32 %131
}

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

!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, !6, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 2, !6, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !11, i64 2}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @arm_mat_solve_lower_triangular_f64(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = load i16, ptr %2, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %2, i64 2
  %12 = load i16, ptr %11, align 2, !tbaa !12
  %.not59.not = icmp eq i16 %12, 0
  %.not63 = icmp eq i16 %10, 0
  %or.cond = select i1 %.not59.not, i1 true, i1 %.not63
  br i1 %or.cond, label %.critedge, label %.lr.ph57.us.preheader

.lr.ph57.us.preheader:                            ; preds = %3
  %13 = zext i16 %12 to i64
  %14 = zext i16 %10 to i64
  br label %.lr.ph57.us

.lr.ph57.us:                                      ; preds = %.lr.ph57.us.preheader, %._crit_edge58.us
  %indvars.iv73 = phi i64 [ 0, %.lr.ph57.us.preheader ], [ %indvars.iv.next74, %._crit_edge58.us ]
  %15 = getelementptr inbounds double, ptr %9, i64 %indvars.iv73
  %invariant.gep = getelementptr inbounds double, ptr %5, i64 %indvars.iv73
  %invariant.gep78 = getelementptr inbounds double, ptr %5, i64 %indvars.iv73
  br label %16

16:                                               ; preds = %.lr.ph57.us, %32
  %indvars.iv68 = phi i64 [ 0, %.lr.ph57.us ], [ %indvars.iv.next69, %32 ]
  %17 = mul nuw nsw i64 %indvars.iv68, %13
  %18 = getelementptr inbounds double, ptr %15, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !13
  %20 = mul nuw nsw i64 %indvars.iv68, %14
  %21 = getelementptr inbounds double, ptr %7, i64 %20
  %.not64 = icmp eq i64 %indvars.iv68, 0
  br i1 %.not64, label %._crit_edge.us, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %16
  %xtraiter = and i64 %indvars.iv68, 1
  %22 = icmp eq i64 %indvars.iv68, 1
  br i1 %22, label %._crit_edge.us.loopexit.unr-lcssa, label %.lr.ph.us.preheader.new

.lr.ph.us.preheader.new:                          ; preds = %.lr.ph.us.preheader
  %unroll_iter = and i64 %indvars.iv68, 9223372036854775806
  br label %.lr.ph.us

._crit_edge.us.loopexit.unr-lcssa:                ; preds = %.lr.ph.us, %.lr.ph.us.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.us.preheader ], [ %45, %.lr.ph.us ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next.1, %.lr.ph.us ]
  %.04354.us.unr = phi double [ %19, %.lr.ph.us.preheader ], [ %45, %.lr.ph.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.lr.ph.us.epil

.lr.ph.us.epil:                                   ; preds = %._crit_edge.us.loopexit.unr-lcssa
  %23 = getelementptr inbounds double, ptr %21, i64 %indvars.iv.unr
  %24 = load double, ptr %23, align 8, !tbaa !13
  %25 = mul nuw nsw i64 %indvars.iv.unr, %13
  %gep.epil = getelementptr inbounds double, ptr %invariant.gep, i64 %25
  %26 = load double, ptr %gep.epil, align 8, !tbaa !13
  %27 = fneg double %24
  %28 = tail call double @llvm.fmuladd.f64(double %27, double %26, double %.04354.us.unr)
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.lr.ph.us.epil, %._crit_edge.us.loopexit.unr-lcssa, %16
  %.043.lcssa.us = phi double [ %19, %16 ], [ %.lcssa.ph, %._crit_edge.us.loopexit.unr-lcssa ], [ %28, %.lr.ph.us.epil ]
  %29 = getelementptr inbounds double, ptr %21, i64 %indvars.iv68
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = fcmp une double %30, 0.000000e+00
  br i1 %31, label %32, label %.critedge

32:                                               ; preds = %._crit_edge.us
  %33 = fdiv double %.043.lcssa.us, %30
  %gep79 = getelementptr inbounds double, ptr %invariant.gep78, i64 %17
  store double %33, ptr %gep79, align 8, !tbaa !13
  %indvars.iv.next69 = add nuw nsw i64 %indvars.iv68, 1
  %exitcond72.not = icmp eq i64 %indvars.iv.next69, %14
  br i1 %exitcond72.not, label %._crit_edge58.us, label %16, !llvm.loop !15

.lr.ph.us:                                        ; preds = %.lr.ph.us, %.lr.ph.us.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.us.preheader.new ], [ %indvars.iv.next.1, %.lr.ph.us ]
  %.04354.us = phi double [ %19, %.lr.ph.us.preheader.new ], [ %45, %.lr.ph.us ]
  %niter = phi i64 [ 0, %.lr.ph.us.preheader.new ], [ %niter.next.1, %.lr.ph.us ]
  %34 = getelementptr inbounds double, ptr %21, i64 %indvars.iv
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = mul nuw nsw i64 %indvars.iv, %13
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %36
  %37 = load double, ptr %gep, align 8, !tbaa !13
  %38 = fneg double %35
  %39 = tail call double @llvm.fmuladd.f64(double %38, double %37, double %.04354.us)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %40 = getelementptr inbounds double, ptr %21, i64 %indvars.iv.next
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = mul nuw nsw i64 %indvars.iv.next, %13
  %gep.1 = getelementptr inbounds double, ptr %invariant.gep, i64 %42
  %43 = load double, ptr %gep.1, align 8, !tbaa !13
  %44 = fneg double %41
  %45 = tail call double @llvm.fmuladd.f64(double %44, double %43, double %39)
  %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 %._crit_edge.us.loopexit.unr-lcssa, label %.lr.ph.us, !llvm.loop !17

._crit_edge58.us:                                 ; preds = %32
  %indvars.iv.next74 = add nuw nsw i64 %indvars.iv73, 1
  %exitcond76.not = icmp eq i64 %indvars.iv.next74, %13
  br i1 %exitcond76.not, label %.critedge, label %.lr.ph57.us, !llvm.loop !18

.critedge:                                        ; preds = %._crit_edge58.us, %._crit_edge.us, %3
  %spec.select = phi i32 [ 0, %3 ], [ -5, %._crit_edge.us ], [ 0, %._crit_edge58.us ]
  ret i32 %spec.select
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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" }

!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, !10, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 2, !10, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 2}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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