; LLVM IR from microsoft/LightAIMD :: src (matrix)

; 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: 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @inverse_lower_triangular(i64 noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = mul i64 %15, %16
  %18 = mul i64 %17, 8
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 %18, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %103, %3
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %106

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %99, %24
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %102

30:                                               ; preds = %25
  %31 = load i64, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = icmp eq i64 %31, %32
  br i1 %33, label %34, label %49

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = load i64, ptr %7, align 8, !tbaa !5
  %37 = mul nsw i64 %36, %12
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load i64, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %38, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = fdiv double 1.000000e+00, %41
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = mul nsw i64 %44, %13
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  %47 = load i64, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %46, i64 %47
  store double %42, ptr %48, align 8, !tbaa !11
  br label %98

49:                                               ; preds = %30
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %9, align 8, !tbaa !5
  %52 = icmp ugt i64 %50, %51
  br i1 %52, label %53, label %97

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %54 = load i64, ptr %9, align 8, !tbaa !5
  store i64 %54, ptr %11, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %77, %53
  %56 = load i64, ptr %11, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = icmp ult i64 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %80

60:                                               ; preds = %55
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = load i64, ptr %7, align 8, !tbaa !5
  %63 = mul nsw i64 %62, %12
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  %65 = load i64, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  %69 = load i64, ptr %11, align 8, !tbaa !5
  %70 = mul nsw i64 %69, %13
  %71 = getelementptr inbounds double, ptr %68, i64 %70
  %72 = load i64, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds double, ptr %71, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = load double, ptr %10, align 8, !tbaa !11
  %76 = call double @llvm.fmuladd.f64(double %67, double %74, double %75)
  store double %76, ptr %10, align 8, !tbaa !11
  br label %77

77:                                               ; preds = %60
  %78 = load i64, ptr %11, align 8, !tbaa !5
  %79 = add i64 %78, 1
  store i64 %79, ptr %11, align 8, !tbaa !5
  br label %55, !llvm.loop !13

80:                                               ; preds = %59
  %81 = load double, ptr %10, align 8, !tbaa !11
  %82 = fneg double %81
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = load i64, ptr %7, align 8, !tbaa !5
  %85 = mul nsw i64 %84, %12
  %86 = getelementptr inbounds double, ptr %83, i64 %85
  %87 = load i64, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds double, ptr %86, i64 %87
  %89 = load double, ptr %88, align 8, !tbaa !11
  %90 = fdiv double %82, %89
  %91 = load ptr, ptr %6, align 8, !tbaa !9
  %92 = load i64, ptr %7, align 8, !tbaa !5
  %93 = mul nsw i64 %92, %13
  %94 = getelementptr inbounds double, ptr %91, i64 %93
  %95 = load i64, ptr %9, align 8, !tbaa !5
  %96 = getelementptr inbounds double, ptr %94, i64 %95
  store double %90, ptr %96, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %97

97:                                               ; preds = %80, %49
  br label %98

98:                                               ; preds = %97, %34
  br label %99

99:                                               ; preds = %98
  %100 = load i64, ptr %9, align 8, !tbaa !5
  %101 = add i64 %100, 1
  store i64 %101, ptr %9, align 8, !tbaa !5
  br label %25, !llvm.loop !15

102:                                              ; preds = %29
  br label %103

103:                                              ; preds = %102
  %104 = load i64, ptr %7, align 8, !tbaa !5
  %105 = add i64 %104, 1
  store i64 %105, ptr %7, align 8, !tbaa !5
  br label %19, !llvm.loop !16

106:                                              ; preds = %23
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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}


; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @inverse_lower_triangular(i64 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2) local_unnamed_addr #2 {
  %4 = shl i64 %0, 3
  %5 = mul i64 %4, %0
  tail call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 %5, i1 false)
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.preheader42

.preheader42:                                     ; preds = %3, %11
  %.04048 = phi i64 [ %12, %11 ], [ 0, %3 ]
  %invariant.gep45 = getelementptr double, ptr %1, i64 %.04048
  %6 = mul nsw i64 %.04048, %0
  %7 = getelementptr inbounds double, ptr %1, i64 %6
  %gep46 = getelementptr double, ptr %invariant.gep45, i64 %6
  %8 = getelementptr inbounds double, ptr %2, i64 %6
  %9 = getelementptr inbounds double, ptr %7, i64 %.04048
  %10 = getelementptr inbounds double, ptr %8, i64 %.04048
  br label %13

._crit_edge:                                      ; preds = %11, %3
  ret void

11:                                               ; preds = %33
  %12 = add nuw i64 %.04048, 1
  %exitcond49.not = icmp eq i64 %12, %0
  br i1 %exitcond49.not, label %._crit_edge, label %.preheader42, !llvm.loop !5

13:                                               ; preds = %.preheader42, %33
  %.03947 = phi i64 [ 0, %.preheader42 ], [ %34, %33 ]
  %14 = icmp eq i64 %.04048, %.03947
  br i1 %14, label %15, label %18

15:                                               ; preds = %13
  %16 = load double, ptr %9, align 8, !tbaa !7
  %17 = fdiv double 1.000000e+00, %16
  store double %17, ptr %10, align 8, !tbaa !7
  br label %33

18:                                               ; preds = %13
  %19 = icmp ugt i64 %.04048, %.03947
  br i1 %19, label %.preheader, label %33

.preheader:                                       ; preds = %18
  %invariant.gep = getelementptr double, ptr %2, i64 %.03947
  br label %25

20:                                               ; preds = %25
  %21 = fneg double %30
  %22 = load double, ptr %gep46, align 8, !tbaa !7
  %23 = fdiv double %21, %22
  %24 = getelementptr inbounds double, ptr %8, i64 %.03947
  store double %23, ptr %24, align 8, !tbaa !7
  br label %33

25:                                               ; preds = %.preheader, %25
  %.044 = phi i64 [ %.03947, %.preheader ], [ %31, %25 ]
  %.03843 = phi double [ 0.000000e+00, %.preheader ], [ %30, %25 ]
  %26 = getelementptr inbounds double, ptr %7, i64 %.044
  %27 = load double, ptr %26, align 8, !tbaa !7
  %28 = mul nsw i64 %.044, %0
  %gep = getelementptr double, ptr %invariant.gep, i64 %28
  %29 = load double, ptr %gep, align 8, !tbaa !7
  %30 = tail call double @llvm.fmuladd.f64(double %27, double %29, double %.03843)
  %31 = add nuw i64 %.044, 1
  %32 = icmp ult i64 %31, %.04048
  br i1 %32, label %25, label %20, !llvm.loop !11

33:                                               ; preds = %15, %20, %18
  %34 = add nuw i64 %.03947, 1
  %exitcond.not = icmp eq i64 %34, %0
  br i1 %exitcond.not, label %11, label %13, !llvm.loop !12
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass