; 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_upper_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 = %125, %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 %128

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
  %47 = load i32, ptr %12, align 4, !tbaa !13
  %48 = sub nsw i32 %47, 1
  store i32 %48, ptr %9, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %121, %42
  %50 = load i32, ptr %9, align 4, !tbaa !13
  %51 = icmp sge i32 %50, 0
  br i1 %51, label %52, label %124

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

68:                                               ; preds = %90, %52
  %69 = load i32, ptr %11, align 4, !tbaa !13
  %70 = load i32, ptr %9, align 4, !tbaa !13
  %71 = icmp sgt i32 %69, %70
  br i1 %71, label %72, label %93

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

90:                                               ; preds = %72
  %91 = load i32, ptr %11, align 4, !tbaa !13
  %92 = add nsw i32 %91, -1
  store i32 %92, ptr %11, align 4, !tbaa !13
  br label %68, !llvm.loop !18

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

100:                                              ; preds = %93
  store i32 -5, ptr %4, align 4
  store i32 1, ptr %20, align 4
  br label %118

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

118:                                              ; preds = %101, %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  %119 = load i32, ptr %20, align 4
  switch i32 %119, label %129 [
    i32 0, label %120
  ]

120:                                              ; preds = %118
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %9, align 4, !tbaa !13
  %123 = add nsw i32 %122, -1
  store i32 %123, ptr %9, align 4, !tbaa !13
  br label %49, !llvm.loop !20

124:                                              ; preds = %49
  br label %125

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

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

129:                                              ; preds = %128, %118
  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
  %130 = load i32, ptr %20, align 4
  switch i32 %130, label %133 [
    i32 0, label %131
  ]

131:                                              ; preds = %129
  %132 = load i32, ptr %8, align 4, !tbaa !13
  store i32 %132, ptr %4, align 4
  store i32 1, ptr %20, align 4
  br label %133

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

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_upper_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 %10 to i64
  %14 = add nsw i64 %13, -1
  %15 = zext i16 %10 to i64
  %16 = add nsw i64 %15, -1
  %17 = zext i16 %12 to i64
  %18 = zext i16 %10 to i64
  %wide.trip.count = zext i16 %12 to i64
  %19 = mul nuw nsw i64 %16, %17
  %indvars.iv.next.prol = add nsw i64 %15, -2
  br label %.lr.ph57.us

.lr.ph57.us:                                      ; preds = %.lr.ph57.us.preheader, %._crit_edge58.us
  %indvars.iv70 = phi i64 [ 0, %.lr.ph57.us.preheader ], [ %indvars.iv.next71, %._crit_edge58.us ]
  %20 = getelementptr inbounds double, ptr %9, i64 %indvars.iv70
  %invariant.gep = getelementptr double, ptr %5, i64 %indvars.iv70
  %invariant.gep74 = getelementptr double, ptr %5, i64 %indvars.iv70
  %gep.prol = getelementptr double, ptr %invariant.gep, i64 %19
  br label %21

21:                                               ; preds = %.lr.ph57.us, %37
  %indvar = phi i64 [ 0, %.lr.ph57.us ], [ %indvar.next, %37 ]
  %indvars.iv67 = phi i64 [ %16, %.lr.ph57.us ], [ %indvars.iv.next68, %37 ]
  %22 = mul nuw nsw i64 %indvars.iv67, %17
  %23 = getelementptr inbounds double, ptr %20, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !13
  %25 = mul nuw nsw i64 %indvars.iv67, %18
  %26 = getelementptr inbounds double, ptr %7, i64 %25
  %27 = icmp sgt i64 %14, %indvars.iv67
  br i1 %27, label %.lr.ph.us.preheader, label %._crit_edge.us

.lr.ph.us.preheader:                              ; preds = %21
  %xtraiter = and i64 %indvar, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.us.prol.loopexit, label %.lr.ph.us.prol

.lr.ph.us.prol:                                   ; preds = %.lr.ph.us.preheader
  %28 = getelementptr inbounds double, ptr %26, i64 %16
  %29 = load double, ptr %28, align 8, !tbaa !13
  %30 = load double, ptr %gep.prol, align 8, !tbaa !13
  %31 = fneg double %29
  %32 = tail call double @llvm.fmuladd.f64(double %31, double %30, double %24)
  br label %.lr.ph.us.prol.loopexit

.lr.ph.us.prol.loopexit:                          ; preds = %.lr.ph.us.prol, %.lr.ph.us.preheader
  %indvars.iv.unr = phi i64 [ %16, %.lr.ph.us.preheader ], [ %indvars.iv.next.prol, %.lr.ph.us.prol ]
  %.04454.us.unr = phi double [ %24, %.lr.ph.us.preheader ], [ %32, %.lr.ph.us.prol ]
  %.lcssa.unr = phi double [ poison, %.lr.ph.us.preheader ], [ %32, %.lr.ph.us.prol ]
  %33 = icmp eq i64 %indvar, 1
  br i1 %33, label %._crit_edge.us, label %.lr.ph.us

._crit_edge.us:                                   ; preds = %.lr.ph.us.prol.loopexit, %.lr.ph.us, %21
  %.044.lcssa.us = phi double [ %24, %21 ], [ %.lcssa.unr, %.lr.ph.us.prol.loopexit ], [ %51, %.lr.ph.us ]
  %34 = getelementptr inbounds double, ptr %26, i64 %indvars.iv67
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = fcmp une double %35, 0.000000e+00
  br i1 %36, label %37, label %.critedge

37:                                               ; preds = %._crit_edge.us
  %38 = fdiv double %.044.lcssa.us, %35
  %gep75 = getelementptr double, ptr %invariant.gep74, i64 %22
  store double %38, ptr %gep75, align 8, !tbaa !13
  %indvars.iv.next68 = add nsw i64 %indvars.iv67, -1
  %39 = icmp sgt i64 %indvars.iv67, 0
  %indvar.next = add i64 %indvar, 1
  br i1 %39, label %21, label %._crit_edge58.us, !llvm.loop !15

.lr.ph.us:                                        ; preds = %.lr.ph.us.prol.loopexit, %.lr.ph.us
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph.us ], [ %indvars.iv.unr, %.lr.ph.us.prol.loopexit ]
  %.04454.us = phi double [ %51, %.lr.ph.us ], [ %.04454.us.unr, %.lr.ph.us.prol.loopexit ]
  %40 = getelementptr inbounds double, ptr %26, i64 %indvars.iv
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = mul nuw nsw i64 %indvars.iv, %17
  %gep = getelementptr double, ptr %invariant.gep, i64 %42
  %43 = load double, ptr %gep, align 8, !tbaa !13
  %44 = fneg double %41
  %45 = tail call double @llvm.fmuladd.f64(double %44, double %43, double %.04454.us)
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %46 = getelementptr inbounds double, ptr %26, i64 %indvars.iv.next
  %47 = load double, ptr %46, align 8, !tbaa !13
  %48 = mul nuw nsw i64 %indvars.iv.next, %17
  %gep.1 = getelementptr double, ptr %invariant.gep, i64 %48
  %49 = load double, ptr %gep.1, align 8, !tbaa !13
  %50 = fneg double %47
  %51 = tail call double @llvm.fmuladd.f64(double %50, double %49, double %45)
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %52 = icmp sgt i64 %indvars.iv.next.1, %indvars.iv67
  br i1 %52, label %.lr.ph.us, label %._crit_edge.us, !llvm.loop !17

._crit_edge58.us:                                 ; preds = %37
  %indvars.iv.next71 = add nuw nsw i64 %indvars.iv70, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next71, %wide.trip.count
  br i1 %exitcond.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