; 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: nounwind uwtable
define dso_local double @matnorm(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %45, %3
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %48

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = mul i64 %19, %20
  store i64 %21, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %41, %18
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = add i64 %28, %29
  store i64 %30, ptr %12, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %12, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i64, ptr %12, align 8, !tbaa !9
  %37 = getelementptr inbounds double, ptr %35, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = load double, ptr %7, align 8, !tbaa !11
  %40 = call double @llvm.fmuladd.f64(double %34, double %38, double %39)
  store double %40, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %41

41:                                               ; preds = %27
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %11, align 8, !tbaa !9
  br label %22, !llvm.loop !13

44:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %8, align 8, !tbaa !9
  br label %13, !llvm.loop !15

48:                                               ; preds = %17
  %49 = load double, ptr %7, align 8, !tbaa !11
  %50 = call double @sqrt(double noundef %49) #4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %50
}

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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


; 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: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local double @matnorm(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  %.not25 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not25
  br i1 %or.cond, label %._crit_edge23, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %3
  %4 = add i64 %2, -1
  %xtraiter = and i64 %2, 3
  %5 = icmp ult i64 %4, 3
  %unroll_iter = and i64 %2, -4
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.020.us = phi double [ %.lcssa, %._crit_edge.us ], [ 0.000000e+00, %.lr.ph.us.preheader ]
  %.01619.us = phi i64 [ %28, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %6 = mul i64 %.01619.us, %2
  %7 = getelementptr double, ptr %0, i64 %6
  br i1 %5, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %.118.us = phi double [ %22, %.lr.ph.us.new ], [ %.020.us, %.lr.ph.us ]
  %.01517.us = phi i64 [ %23, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %8 = getelementptr double, ptr %7, i64 %.01517.us
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %.118.us)
  %11 = or disjoint i64 %.01517.us, 1
  %12 = getelementptr double, ptr %7, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %10)
  %15 = or disjoint i64 %.01517.us, 2
  %16 = getelementptr double, ptr %7, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %14)
  %19 = or disjoint i64 %.01517.us, 3
  %20 = getelementptr double, ptr %7, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %18)
  %23 = add nuw i64 %.01517.us, 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.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.lcssa.ph = phi double [ poison, %.lr.ph.us ], [ %22, %.lr.ph.us.new ]
  %.118.us.unr = phi double [ %.020.us, %.lr.ph.us ], [ %22, %.lr.ph.us.new ]
  %.01517.us.unr = phi i64 [ 0, %.lr.ph.us ], [ %23, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.118.us.epil = phi double [ %26, %.epil.preheader ], [ %.118.us.unr, %._crit_edge.us.unr-lcssa ]
  %.01517.us.epil = phi i64 [ %27, %.epil.preheader ], [ %.01517.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %24 = getelementptr double, ptr %7, i64 %.01517.us.epil
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %.118.us.epil)
  %27 = add nuw i64 %.01517.us.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.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %26, %.epil.preheader ]
  %28 = add nuw i64 %.01619.us, 1
  %exitcond27.not = icmp eq i64 %28, %1
  br i1 %exitcond27.not, label %._crit_edge23, label %.lr.ph.us, !llvm.loop !13

._crit_edge23:                                    ; preds = %._crit_edge.us, %3
  %.0.lcssa = phi double [ 0.000000e+00, %3 ], [ %.lcssa, %._crit_edge.us ]
  %29 = tail call double @sqrt(double noundef %.0.lcssa) #3
  ret double %29
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

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


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