; 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: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @cholesky_decompose(ptr noundef %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %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) #5
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %103, %3
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %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) #5
  br label %106

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = mul i64 %25, %26
  store i64 %27, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %99, %24
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = add i64 %30, 1
  %32 = icmp ult i64 %29, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = mul i64 %35, %36
  store i64 %37, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %58, %34
  %39 = load i64, ptr %13, align 8, !tbaa !9
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %61

43:                                               ; preds = %38
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = load i64, ptr %13, align 8, !tbaa !9
  %47 = add i64 %45, %46
  %48 = getelementptr inbounds double, ptr %44, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i64, ptr %12, align 8, !tbaa !9
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = add i64 %51, %52
  %54 = getelementptr inbounds double, ptr %50, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = load double, ptr %11, align 8, !tbaa !11
  %57 = call double @llvm.fmuladd.f64(double %49, double %55, double %56)
  store double %57, ptr %11, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %43
  %59 = load i64, ptr %13, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %13, align 8, !tbaa !9
  br label %38, !llvm.loop !13

61:                                               ; preds = %42
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = icmp eq i64 %62, %63
  br i1 %64, label %65, label %75

65:                                               ; preds = %61
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = load i64, ptr %7, align 8, !tbaa !9
  %69 = add i64 %67, %68
  %70 = getelementptr inbounds double, ptr %66, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = load double, ptr %11, align 8, !tbaa !11
  %73 = fsub double %71, %72
  %74 = call double @sqrt(double noundef %73) #5
  br label %92

75:                                               ; preds = %61
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load i64, ptr %12, align 8, !tbaa !9
  %78 = load i64, ptr %10, align 8, !tbaa !9
  %79 = add i64 %77, %78
  %80 = getelementptr inbounds double, ptr %76, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = fdiv double 1.000000e+00, %81
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load i64, ptr %9, align 8, !tbaa !9
  %85 = load i64, ptr %10, align 8, !tbaa !9
  %86 = add i64 %84, %85
  %87 = getelementptr inbounds double, ptr %83, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !11
  %89 = load double, ptr %11, align 8, !tbaa !11
  %90 = fsub double %88, %89
  %91 = fmul double %82, %90
  br label %92

92:                                               ; preds = %75, %65
  %93 = phi double [ %74, %65 ], [ %91, %75 ]
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = load i64, ptr %9, align 8, !tbaa !9
  %96 = load i64, ptr %10, align 8, !tbaa !9
  %97 = add i64 %95, %96
  %98 = getelementptr inbounds double, ptr %94, i64 %97
  store double %93, ptr %98, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %99

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

102:                                              ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %103

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

106:                                              ; preds = %23
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind "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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"long", !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 nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

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

.loopexit:                                        ; preds = %60
  %indvars.iv.next = add i64 %indvars.iv, 1
  %exitcond56.not = icmp eq i64 %6, %2
  br i1 %exitcond56.not, label %._crit_edge52, label %.lr.ph47, !llvm.loop !5

._crit_edge52:                                    ; preds = %.loopexit, %3
  ret void

.lr.ph47:                                         ; preds = %3, %.loopexit
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 1, %3 ]
  %.03849 = phi i64 [ %6, %.loopexit ], [ 0, %3 ]
  %6 = add nuw i64 %.03849, 1
  %7 = mul i64 %.03849, %2
  %8 = getelementptr double, ptr %1, i64 %7
  %9 = getelementptr double, ptr %0, i64 %7
  %10 = getelementptr double, ptr %9, i64 %.03849
  br label %11

11:                                               ; preds = %.lr.ph47, %60
  %.04045 = phi i64 [ 0, %.lr.ph47 ], [ %63, %60 ]
  %12 = mul i64 %.04045, %2
  %.not54 = icmp eq i64 %.04045, 0
  br i1 %.not54, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %13 = getelementptr double, ptr %1, i64 %12
  %xtraiter = and i64 %.04045, 3
  %14 = icmp ult i64 %.04045, 4
  br i1 %14, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %.04045, -4
  br label %22

._crit_edge.loopexit.unr-lcssa:                   ; preds = %22, %.lr.ph
  %.lcssa.ph = phi double [ poison, %.lr.ph ], [ %45, %22 ]
  %.044.unr = phi i64 [ 0, %.lr.ph ], [ %46, %22 ]
  %.03943.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %45, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %.044.epil = phi i64 [ %20, %.epil.preheader ], [ %.044.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.03943.epil = phi double [ %19, %.epil.preheader ], [ %.03943.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %15 = getelementptr double, ptr %8, i64 %.044.epil
  %16 = load double, ptr %15, align 8, !tbaa !7
  %17 = getelementptr double, ptr %13, i64 %.044.epil
  %18 = load double, ptr %17, align 8, !tbaa !7
  %19 = tail call double @llvm.fmuladd.f64(double %16, double %18, double %.03943.epil)
  %20 = add nuw i64 %.044.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %11
  %.039.lcssa = phi double [ 0.000000e+00, %11 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %19, %.epil.preheader ]
  %21 = icmp eq i64 %.03849, %.04045
  br i1 %21, label %47, label %51

22:                                               ; preds = %22, %.lr.ph.new
  %.044 = phi i64 [ 0, %.lr.ph.new ], [ %46, %22 ]
  %.03943 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %45, %22 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %22 ]
  %23 = getelementptr double, ptr %8, i64 %.044
  %24 = load double, ptr %23, align 8, !tbaa !7
  %25 = getelementptr double, ptr %13, i64 %.044
  %26 = load double, ptr %25, align 8, !tbaa !7
  %27 = tail call double @llvm.fmuladd.f64(double %24, double %26, double %.03943)
  %28 = or disjoint i64 %.044, 1
  %29 = getelementptr double, ptr %8, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !7
  %31 = getelementptr double, ptr %13, i64 %28
  %32 = load double, ptr %31, align 8, !tbaa !7
  %33 = tail call double @llvm.fmuladd.f64(double %30, double %32, double %27)
  %34 = or disjoint i64 %.044, 2
  %35 = getelementptr double, ptr %8, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !7
  %37 = getelementptr double, ptr %13, i64 %34
  %38 = load double, ptr %37, align 8, !tbaa !7
  %39 = tail call double @llvm.fmuladd.f64(double %36, double %38, double %33)
  %40 = or disjoint i64 %.044, 3
  %41 = getelementptr double, ptr %8, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !7
  %43 = getelementptr double, ptr %13, i64 %40
  %44 = load double, ptr %43, align 8, !tbaa !7
  %45 = tail call double @llvm.fmuladd.f64(double %42, double %44, double %39)
  %46 = add nuw i64 %.044, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %22, !llvm.loop !13

47:                                               ; preds = %._crit_edge
  %48 = load double, ptr %10, align 8, !tbaa !7
  %49 = fsub double %48, %.039.lcssa
  %50 = tail call double @sqrt(double noundef %49) #4
  br label %60

51:                                               ; preds = %._crit_edge
  %52 = getelementptr double, ptr %1, i64 %12
  %53 = getelementptr double, ptr %52, i64 %.04045
  %54 = load double, ptr %53, align 8, !tbaa !7
  %55 = fdiv double 1.000000e+00, %54
  %56 = getelementptr double, ptr %9, i64 %.04045
  %57 = load double, ptr %56, align 8, !tbaa !7
  %58 = fsub double %57, %.039.lcssa
  %59 = fmul double %55, %58
  br label %60

60:                                               ; preds = %51, %47
  %61 = phi double [ %50, %47 ], [ %59, %51 ]
  %62 = getelementptr double, ptr %8, i64 %.04045
  store double %61, ptr %62, align 8, !tbaa !7
  %63 = add nuw i64 %.04045, 1
  %exitcond55.not = icmp eq i64 %63, %indvars.iv
  br i1 %exitcond55.not, label %.loopexit, label %11, !llvm.loop !14
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 #2 = { nofree nounwind memory(write, 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = 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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !6}
!14 = distinct !{!14, !6}


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